Skip to content

Commit c26197a

Browse files
committed
Added more documentation.
1 parent 9559099 commit c26197a

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

src/mpi/mpi_caf.c

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,33 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4949

5050

5151
#ifdef GCC_GE_7
52-
/* This data structure is owned by the library and is treated
53-
as a black box by the compiler.
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.
5461
*/
5562
typedef struct mpi_caf_token_t
56-
{
57-
void *local_memptr; /* local data. not stored by the compiler -- useful for freeing the memory in deregister */
58-
MPI_Win memptr; /* holds the data -- used to be the token returned by register (which now returns nothing) */
59-
MPI_Win *desc; /* useful for checking dimensions, etc. */
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. */
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. */
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. */
78+
MPI_Win *desc;
6079
} mpi_caf_token_t;
6180
#define TOKEN(X) &(((mpi_caf_token_t *) (X))->memptr)
6281
#else
@@ -459,6 +478,7 @@ PREFIX (finalize) (void)
459478
p = TOKEN(tmp_tot->token);
460479
CAF_Win_unlock_all (*p);
461480
#ifdef GCC_GE_7
481+
/* Unregister the window to the descriptors when freeing the token. */
462482
if (((mpi_caf_token_t *)tmp_tot->token)->desc)
463483
{
464484
mpi_caf_token_t *mpi_token = (mpi_caf_token_t *)tmp_tot->token;
@@ -506,6 +526,17 @@ PREFIX (num_images)(int distance __attribute__ ((unused)),
506526

507527

508528
#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+
*/
509540
void
510541
PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
511542
gfc_descriptor_t *desc, int *stat, char *errmsg,
@@ -535,6 +566,8 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
535566

536567
mpi_caf_token_t *mpi_token;
537568
MPI_Win *p;
569+
/* The token has to be present, when COARRAY_ALLOC_ALLOCATE_ONLY is
570+
specified. */
538571
if (type != CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY)
539572
*token = malloc (sizeof (mpi_caf_token_t));
540573

@@ -546,6 +579,7 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
546579
|| type == CAF_REGTYPE_COARRAY_STATIC)
547580
&& GFC_DESCRIPTOR_RANK (desc) != 0)
548581
{
582+
/* Add a window for the descriptor when an array is registered. */
549583
int ierr;
550584
size_t desc_size = sizeof (gfc_descriptor_t) + /*GFC_DESCRIPTOR_RANK (desc)*/
551585
GFC_MAX_DIMENSIONS * sizeof (descriptor_dimension);
@@ -1713,6 +1747,9 @@ PREFIX (get) (caf_token_t token, size_t offset,
17131747
/* Emitted when a theorectically unreachable part is reached. */
17141748
const char unreachable[] = "Fatal error: unreachable alternative found.\n";
17151749

1750+
/** Convert kind 4 characters into kind 1 one.
1751+
Copied from the gcc:libgfortran/caf/single.c.
1752+
*/
17161753
static void
17171754
assign_char4_from_char1 (size_t dst_size, size_t src_size, uint32_t *dst,
17181755
unsigned char *src)
@@ -1726,6 +1763,9 @@ assign_char4_from_char1 (size_t dst_size, size_t src_size, uint32_t *dst,
17261763
}
17271764

17281765

1766+
/** Convert kind 1 characters into kind 4 one.
1767+
Copied from the gcc:libgfortran/caf/single.c.
1768+
*/
17291769
static void
17301770
assign_char1_from_char4 (size_t dst_size, size_t src_size, unsigned char *dst,
17311771
uint32_t *src)
@@ -1738,6 +1778,10 @@ assign_char1_from_char4 (size_t dst_size, size_t src_size, unsigned char *dst,
17381778
memset (&dst[n], ' ', dst_size - n);
17391779
}
17401780

1781+
1782+
/** Convert convertable types.
1783+
Copied from the gcc:libgfortran/caf/single.c. Can't say much about it.
1784+
*/
17411785
static void
17421786
convert_type (void *dst, int dst_type, int dst_kind, void *src, int src_type,
17431787
int src_kind, int *stat)
@@ -2000,6 +2044,11 @@ convert_type (void *dst, int dst_type, int dst_kind, void *src, int src_type,
20002044
}
20012045

20022046

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+
*/
20032052
static void
20042053
copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20052054
int src_type, int dst_kind, int src_kind, size_t dst_size,
@@ -2061,6 +2110,10 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20612110
}
20622111

20632112

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. */
20642117
#define COMPUTE_NUM_ITEMS(num, stride, lb, ub) \
20652118
do { \
20662119
ptrdiff_t abs_stride = (stride) > 0 ? (stride) : -(stride); \
@@ -2070,10 +2123,17 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20702123
} while (0)
20712124

20722125

2126+
/** Convenience macro to get the extent of a descriptor in a certain dimension.
2127+
2128+
Copied from gcc:libgfortran/libgfortran.h. */
20732129
#define GFC_DESCRIPTOR_EXTENT(desc,i) ((desc)->dim[i]._ubound + 1 \
20742130
- (desc)->dim[i].lower_bound)
20752131

20762132

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. */
20772137
#define GET_REMOTE_DESC(mpi_token, src, src_desc_data, image_index) \
20782138
if (mpi_token->desc) \
20792139
{ \
@@ -2090,6 +2150,10 @@ copy_data (void *ds, mpi_caf_token_t *token, ptrdiff_t offset, int dst_type,
20902150
src = NULL
20912151

20922152

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. */
20932157
typedef struct gfc_max_dim_descriptor_t {
20942158
void *base_addr;
20952159
size_t offset;

0 commit comments

Comments
 (0)