@@ -49,10 +49,32 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
49
49
50
50
51
51
#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
+ */
52
62
typedef struct mpi_caf_token_t
53
63
{
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. */
54
70
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. */
55
74
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. */
56
78
MPI_Win * desc ;
57
79
} mpi_caf_token_t ;
58
80
#define TOKEN (X ) &(((mpi_caf_token_t *) (X))->memptr)
@@ -456,6 +478,7 @@ PREFIX (finalize) (void)
456
478
p = TOKEN (tmp_tot -> token );
457
479
CAF_Win_unlock_all (* p );
458
480
#ifdef GCC_GE_7
481
+ /* Unregister the window to the descriptors when freeing the token. */
459
482
if (((mpi_caf_token_t * )tmp_tot -> token )-> desc )
460
483
{
461
484
mpi_caf_token_t * mpi_token = (mpi_caf_token_t * )tmp_tot -> token ;
@@ -503,6 +526,17 @@ PREFIX (num_images)(int distance __attribute__ ((unused)),
503
526
504
527
505
528
#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
+ */
506
540
void
507
541
PREFIX (register) (size_t size , caf_register_t type , caf_token_t * token ,
508
542
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,
532
566
533
567
mpi_caf_token_t * mpi_token ;
534
568
MPI_Win * p ;
569
+ /* The token has to be present, when COARRAY_ALLOC_ALLOCATE_ONLY is
570
+ specified. */
535
571
if (type != CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY )
536
572
* token = malloc (sizeof (mpi_caf_token_t ));
537
573
@@ -543,6 +579,7 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
543
579
|| type == CAF_REGTYPE_COARRAY_STATIC )
544
580
&& GFC_DESCRIPTOR_RANK (desc ) != 0 )
545
581
{
582
+ /* Add a window for the descriptor when an array is registered. */
546
583
int ierr ;
547
584
size_t desc_size = sizeof (gfc_descriptor_t ) + /*GFC_DESCRIPTOR_RANK (desc)*/
548
585
GFC_MAX_DIMENSIONS * sizeof (descriptor_dimension );
@@ -1710,6 +1747,9 @@ PREFIX (get) (caf_token_t token, size_t offset,
1710
1747
/* Emitted when a theorectically unreachable part is reached. */
1711
1748
const char unreachable [] = "Fatal error: unreachable alternative found.\n" ;
1712
1749
1750
+ /** Convert kind 4 characters into kind 1 one.
1751
+ Copied from the gcc:libgfortran/caf/single.c.
1752
+ */
1713
1753
static void
1714
1754
assign_char4_from_char1 (size_t dst_size , size_t src_size , uint32_t * dst ,
1715
1755
unsigned char * src )
@@ -1723,6 +1763,9 @@ assign_char4_from_char1 (size_t dst_size, size_t src_size, uint32_t *dst,
1723
1763
}
1724
1764
1725
1765
1766
+ /** Convert kind 1 characters into kind 4 one.
1767
+ Copied from the gcc:libgfortran/caf/single.c.
1768
+ */
1726
1769
static void
1727
1770
assign_char1_from_char4 (size_t dst_size , size_t src_size , unsigned char * dst ,
1728
1771
uint32_t * src )
@@ -1735,6 +1778,10 @@ assign_char1_from_char4 (size_t dst_size, size_t src_size, unsigned char *dst,
1735
1778
memset (& dst [n ], ' ' , dst_size - n );
1736
1779
}
1737
1780
1781
+
1782
+ /** Convert convertable types.
1783
+ Copied from the gcc:libgfortran/caf/single.c. Can't say much about it.
1784
+ */
1738
1785
static void
1739
1786
convert_type (void * dst , int dst_type , int dst_kind , void * src , int src_type ,
1740
1787
int src_kind , int * stat )
@@ -1997,6 +2044,11 @@ convert_type (void *dst, int dst_type, int dst_kind, void *src, int src_type,
1997
2044
}
1998
2045
1999
2046
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
+ */
2000
2052
static void
2001
2053
copy_data (void * ds , mpi_caf_token_t * token , ptrdiff_t offset , int dst_type ,
2002
2054
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,
2058
2110
}
2059
2111
2060
2112
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. */
2061
2117
#define COMPUTE_NUM_ITEMS (num , stride , lb , ub ) \
2062
2118
do { \
2063
2119
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,
2067
2123
} while (0)
2068
2124
2069
2125
2126
+ /** Convenience macro to get the extent of a descriptor in a certain dimension.
2127
+
2128
+ Copied from gcc:libgfortran/libgfortran.h. */
2070
2129
#define GFC_DESCRIPTOR_EXTENT (desc ,i ) ((desc)->dim[i]._ubound + 1 \
2071
2130
- (desc)->dim[i].lower_bound)
2072
2131
2073
2132
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. */
2074
2137
#define GET_REMOTE_DESC (mpi_token , src , src_desc_data , image_index ) \
2075
2138
if (mpi_token->desc) \
2076
2139
{ \
@@ -2087,6 +2150,10 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
2087
2150
src = NULL
2088
2151
2089
2152
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. */
2090
2157
typedef struct gfc_max_dim_descriptor_t {
2091
2158
void * base_addr ;
2092
2159
size_t offset ;
0 commit comments