@@ -49,10 +49,32 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4949
5050
5151#ifdef GCC_GE_7
52+ /** The caf-token of the mpi-library.
53+
54+ Objects of this data structure are owned by the library and are treated as a
55+ black box by the compiler. In the coarray-program the tokens are opaque
56+ pointers, i.e. black boxes.
57+
58+ For each coarray (allocatable|save|pointer) (scalar|array|event|lock) a token
59+ needs to be present. For components of derived type coarrays a token is
60+ needed only when the component has the allocatable or pointer attribute.
61+ */
5262typedef struct mpi_caf_token_t
5363{
64+ /** The pointer to memory associated to this token's data on the local image.
65+ The compiler uses the address for direct access to the memory of the object
66+ this token is assocated to, i.e., the memory pointed to be local_memptr is
67+ the scalar or array.
68+ When the library is responsible for deleting the memory, then this is the one
69+ to free. */
5470 void * local_memptr ;
71+ /** The MPI window to associated to the object's data.
72+ The window is used to access the data on other images. In pre GCC_GE_7
73+ installations this was the token. */
5574 MPI_Win memptr ;
75+ /** When the object this token is associated to is an array, than this
76+ window gives access to the descriptor on remote images. When the object is
77+ scalar, then this is NULL. */
5678 MPI_Win * desc ;
5779} mpi_caf_token_t ;
5880#define TOKEN (X ) &(((mpi_caf_token_t *) (X))->memptr)
@@ -456,6 +478,7 @@ PREFIX (finalize) (void)
456478 p = TOKEN (tmp_tot -> token );
457479 CAF_Win_unlock_all (* p );
458480#ifdef GCC_GE_7
481+ /* Unregister the window to the descriptors when freeing the token. */
459482 if (((mpi_caf_token_t * )tmp_tot -> token )-> desc )
460483 {
461484 mpi_caf_token_t * mpi_token = (mpi_caf_token_t * )tmp_tot -> token ;
@@ -503,6 +526,17 @@ PREFIX (num_images)(int distance __attribute__ ((unused)),
503526
504527
505528#ifdef GCC_GE_7
529+ /** Register an object with the coarray library creating a token where
530+ necessary/requested.
531+
532+ See the ABI-documentation of gfortran for the expected behavior.
533+ Contrary to this expected behavior is this routine not registering memory
534+ in the descriptor, that is already present. I.e., when the compiler
535+ expects the library to allocate the memory for an object in desc, then
536+ its data_ptr is NULL. This is still missing here. At the moment the
537+ compiler also does not make use of it, but it is contrary to the
538+ documentation.
539+ */
506540void
507541PREFIX (register) (size_t size , caf_register_t type , caf_token_t * token ,
508542 gfc_descriptor_t * desc , int * stat , char * errmsg ,
@@ -532,6 +566,8 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
532566
533567 mpi_caf_token_t * mpi_token ;
534568 MPI_Win * p ;
569+ /* The token has to be present, when COARRAY_ALLOC_ALLOCATE_ONLY is
570+ specified. */
535571 if (type != CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY )
536572 * token = malloc (sizeof (mpi_caf_token_t ));
537573
@@ -543,6 +579,7 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
543579 || type == CAF_REGTYPE_COARRAY_STATIC )
544580 && GFC_DESCRIPTOR_RANK (desc ) != 0 )
545581 {
582+ /* Add a window for the descriptor when an array is registered. */
546583 int ierr ;
547584 size_t desc_size = sizeof (gfc_descriptor_t ) + /*GFC_DESCRIPTOR_RANK (desc)*/
548585 GFC_MAX_DIMENSIONS * sizeof (descriptor_dimension );
@@ -1710,6 +1747,9 @@ PREFIX (get) (caf_token_t token, size_t offset,
17101747/* Emitted when a theorectically unreachable part is reached. */
17111748const char unreachable [] = "Fatal error: unreachable alternative found.\n" ;
17121749
1750+ /** Convert kind 4 characters into kind 1 one.
1751+ Copied from the gcc:libgfortran/caf/single.c.
1752+ */
17131753static void
17141754assign_char4_from_char1 (size_t dst_size , size_t src_size , uint32_t * dst ,
17151755 unsigned char * src )
@@ -1723,6 +1763,9 @@ assign_char4_from_char1 (size_t dst_size, size_t src_size, uint32_t *dst,
17231763}
17241764
17251765
1766+ /** Convert kind 1 characters into kind 4 one.
1767+ Copied from the gcc:libgfortran/caf/single.c.
1768+ */
17261769static void
17271770assign_char1_from_char4 (size_t dst_size , size_t src_size , unsigned char * dst ,
17281771 uint32_t * src )
@@ -1735,6 +1778,10 @@ assign_char1_from_char4 (size_t dst_size, size_t src_size, unsigned char *dst,
17351778 memset (& dst [n ], ' ' , dst_size - n );
17361779}
17371780
1781+
1782+ /** Convert convertable types.
1783+ Copied from the gcc:libgfortran/caf/single.c. Can't say much about it.
1784+ */
17381785static void
17391786convert_type (void * dst , int dst_type , int dst_kind , void * src , int src_type ,
17401787 int src_kind , int * stat )
@@ -1997,6 +2044,11 @@ convert_type (void *dst, int dst_type, int dst_kind, void *src, int src_type,
19972044}
19982045
19992046
2047+ /** Copy a chunk of data from one image to the current one, with type
2048+ conversion.
2049+
2050+ Copied from the gcc:libgfortran/caf/single.c. Can't say much about it.
2051+ */
20002052static void
20012053copy_data (void * ds , mpi_caf_token_t * token , ptrdiff_t offset , int dst_type ,
20022054 int src_type , int dst_kind , int src_kind , size_t dst_size ,
@@ -2058,6 +2110,10 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20582110}
20592111
20602112
2113+ /** Compute the number of items referenced.
2114+
2115+ Computes the number of items between lower bound (lb) and upper bound (ub)
2116+ with respect to the stride taking corner cases into account. */
20612117#define COMPUTE_NUM_ITEMS (num , stride , lb , ub ) \
20622118 do { \
20632119 ptrdiff_t abs_stride = (stride) > 0 ? (stride) : -(stride); \
@@ -2067,10 +2123,17 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20672123 } while (0)
20682124
20692125
2126+ /** Convenience macro to get the extent of a descriptor in a certain dimension.
2127+
2128+ Copied from gcc:libgfortran/libgfortran.h. */
20702129#define GFC_DESCRIPTOR_EXTENT (desc ,i ) ((desc)->dim[i]._ubound + 1 \
20712130 - (desc)->dim[i].lower_bound)
20722131
20732132
2133+ /** Get a copy of the remote descriptor.
2134+
2135+ The copy of the remote descriptor is placed into memory which has to be
2136+ provided in src_desc_data. The pointer to the descriptor is set in src. */
20742137#define GET_REMOTE_DESC (mpi_token , src , src_desc_data , image_index ) \
20752138 if (mpi_token->desc) \
20762139 { \
@@ -2087,6 +2150,10 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20872150 src = NULL
20882151
20892152
2153+ /** Define the descriptor of max rank.
2154+
2155+ This typedef is made to allow storing a copy of a remote descriptor on the
2156+ stack without having to care about the rank. */
20902157typedef struct gfc_max_dim_descriptor_t {
20912158 void * base_addr ;
20922159 size_t offset ;
0 commit comments