]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/doc/gfortran/function-abi-documentation.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / function-abi-documentation.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. _function-abi-documentation:
7
8Function ABI Documentation
9**************************
10
11.. toctree::
12 :maxdepth: 2
13
14
15.. index:: Coarray, _gfortran_caf_init
16
17.. _gfortran_caf_init:
18
19_gfortran_caf_init --- Initialiation function
20^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21
22.. function:: void _gfortran_caf_init (int *argc, char ***argv)
23
24 This function is called at startup of the program before the Fortran main
25 program, if the latter has been compiled with :option:`-fcoarray=lib`.
26 It takes as arguments the command-line arguments of the program. It is
27 permitted to pass two ``NULL`` pointers as argument; if non- ``NULL``,
28 the library is permitted to modify the arguments.
29
30 :param argc:
31 intent(inout) An integer pointer with the number of
32 arguments passed to the program or ``NULL``.
33
34 :param argv:
35 intent(inout) A pointer to an array of strings with the
36 command-line arguments or ``NULL``.
37
38 .. note::
39
40 The function is modelled after the initialization function of the Message
41 Passing Interface (MPI) specification. Due to the way coarray registration
42 works, it might not be the first call to the library. If the main program is
43 not written in Fortran and only a library uses coarrays, it can happen that
44 this function is never called. Therefore, it is recommended that the library
45 does not rely on the passed arguments and whether the call has been done.
46
47.. index:: Coarray, _gfortran_caf_finish
48
49.. _gfortran_caf_finish:
50
51_gfortran_caf_finish --- Finalization function
52^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53
54.. function:: void _gfortran_caf_finish (void)
55
56 This function is called at the end of the Fortran main program, if it has
57 been compiled with the :option:`-fcoarray=lib` option.
58
59 .. note::
60
61 For non-Fortran programs, it is recommended to call the function at the end
62 of the main program. To ensure that the shutdown is also performed for
63 programs where this function is not explicitly invoked, for instance
64 non-Fortran programs or calls to the system's exit() function, the library
65 can use a destructor function. Note that programs can also be terminated
66 using the STOP and ERROR STOP statements; those use different library calls.
67
68.. index:: Coarray, _gfortran_caf_this_image
69
70.. _gfortran_caf_this_image:
71
72_gfortran_caf_this_image --- Querying the image number
73^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74
75.. function:: int _gfortran_caf_this_image (int distance)
76
77 This function returns the current image number, which is a positive number.
78
79 :param distance:
80 As specified for the ``this_image`` intrinsic
81 in TS18508. Shall be a non-negative number.
82
83 .. note::
84
85 If the Fortran intrinsic ``this_image`` is invoked without an argument, which
86 is the only permitted form in Fortran 2008, GCC passes ``0`` as
87 first argument.
88
89.. index:: Coarray, _gfortran_caf_num_images
90
91.. _gfortran_caf_num_images:
92
93_gfortran_caf_num_images --- Querying the maximal number of images
94^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95
96.. function:: int _gfortran_caf_num_images(int distance, int failed)
97
98 This function returns the number of images in the current team, if
99 :samp:`{distance}` is 0 or the number of images in the parent team at the specified
100 distance. If failed is -1, the function returns the number of all images at
101 the specified distance; if it is 0, the function returns the number of
102 nonfailed images, and if it is 1, it returns the number of failed images.
103
104 :param distance:
105 the distance from this image to the ancestor.
106 Shall be positive.
107
108 :param failed:
109 shall be -1, 0, or 1
110
111 .. note::
112
113 This function follows TS18508. If the num_image intrinsic has no arguments,
114 then the compiler passes ``distance=0`` and ``failed=-1`` to the function.
115
116.. index:: Coarray, _gfortran_caf_image_status
117
118.. _gfortran_caf_image_status:
119
120_gfortran_caf_image_status --- Query the status of an image
121^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122
123.. function:: int _gfortran_caf_image_status (int image, caf_team_t * team)
124
125 Get the status of the image given by the id :samp:`{image}` of the team given by
126 :samp:`{team}`. Valid results are zero, for image is ok, ``STAT_STOPPED_IMAGE``
127 from the ISO_FORTRAN_ENV module to indicate that the image has been stopped and
128 ``STAT_FAILED_IMAGE`` also from ISO_FORTRAN_ENV to indicate that the image
129 has executed a ``FAIL IMAGE`` statement.
130
131 :param image:
132 the positive scalar id of the image in the current TEAM.
133
134 :param team:
135 optional; team on the which the inquiry is to be
136 performed.
137
138 .. note::
139
140 This function follows TS18508. Because team-functionality is not yet
141 implemented a null-pointer is passed for the :samp:`{team}` argument at the moment.
142
143.. index:: Coarray, _gfortran_caf_failed_images
144
145.. _gfortran_caf_failed_images:
146
147_gfortran_caf_failed_images --- Get an array of the indexes of the failed images
148^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149
150.. function:: int _gfortran_caf_failed_images (caf_team_t * team, int * kind)
151
152 Get an array of image indexes in the current :samp:`{team}` that have failed. The
153 array is sorted ascendingly. When :samp:`{team}` is not provided the current team
154 is to be used. When :samp:`{kind}` is provided then the resulting array is of that
155 integer kind else it is of default integer kind. The returns an unallocated
156 size zero array when no images have failed.
157
158 :param team:
159 optional; team on the which the inquiry is to be
160 performed.
161
162 :param image:
163 optional; the kind of the resulting integer array.
164
165 .. note::
166
167 This function follows TS18508. Because team-functionality is not yet
168 implemented a null-pointer is passed for the :samp:`{team}` argument at the moment.
169
170.. index:: Coarray, _gfortran_caf_stopped_images
171
172.. _gfortran_caf_stopped_images:
173
174_gfortran_caf_stopped_images --- Get an array of the indexes of the stopped images
175^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176
177.. function:: int _gfortran_caf_stopped_images (caf_team_t * team, int * kind)
178
179 Get an array of image indexes in the current :samp:`{team}` that have stopped. The
180 array is sorted ascendingly. When :samp:`{team}` is not provided the current team
181 is to be used. When :samp:`{kind}` is provided then the resulting array is of that
182 integer kind else it is of default integer kind. The returns an unallocated
183 size zero array when no images have failed.
184
185 :param team:
186 optional; team on the which the inquiry is to be
187 performed.
188
189 :param image:
190 optional; the kind of the resulting integer array.
191
192 .. note::
193
194 This function follows TS18508. Because team-functionality is not yet
195 implemented a null-pointer is passed for the :samp:`{team}` argument at the moment.
196
197.. index:: Coarray, _gfortran_caf_register
198
199.. _gfortran_caf_register:
200
201_gfortran_caf_register --- Registering coarrays
202^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203
204.. function:: void caf_register (size_t size, caf_register_t type, caf_token_t *token, gfc_descriptor_t *desc, int *stat, char *errmsg, size_t errmsg_len)
205
206 Registers memory for a coarray and creates a token to identify the coarray. The
207 routine is called for both coarrays with ``SAVE`` attribute and using an
208 explicit ``ALLOCATE`` statement. If an error occurs and :samp:`{STAT}` is a
209 ``NULL`` pointer, the function shall abort with printing an error message
210 and starting the error termination. If no error occurs and :samp:`{STAT}` is
211 present, it shall be set to zero. Otherwise, it shall be set to a positive
212 value and, if not- ``NULL``, :samp:`{ERRMSG}` shall be set to a string describing
213 the failure. The routine shall register the memory provided in the
214 ``DATA`` -component of the array descriptor :samp:`{DESC}`, when that component
215 is non- ``NULL``, else it shall allocate sufficient memory and provide a
216 pointer to it in the ``DATA`` -component of :samp:`{DESC}`. The array descriptor
217 has rank zero, when a scalar object is to be registered and the array
218 descriptor may be invalid after the call to ``_gfortran_caf_register``.
219 When an array is to be allocated the descriptor persists.
220
221 :param size:
222 For normal coarrays, the byte size of the coarray to be
223 allocated; for lock types and event types, the number of elements.
224
225 :param type:
226 one of the caf_register_t types.
227
228 :param token:
229 intent(out) An opaque pointer identifying the coarray.
230
231 :param desc:
232 intent(inout) The (pseudo) array descriptor.
233
234 :param stat:
235 intent(out) For allocatable coarrays, stores the STAT=;
236 may be ``NULL``
237
238 :param errmsg:
239 intent(out) When an error occurs, this will be set to
240 an error message; may be ``NULL``
241
242 :param errmsg_len:
243 the buffer size of errmsg.
244
245 .. note::
246
247 Nonallocatable coarrays have to be registered prior use from remote images.
248 In order to guarantee this, they have to be registered before the main
249 program. This can be achieved by creating constructor functions. That is what
250 GCC does such that also for nonallocatable coarrays the memory is allocated and
251 no static memory is used. The token permits to identify the coarray; to the
252 processor, the token is a nonaliasing pointer. The library can, for instance,
253 store the base address of the coarray in the token, some handle or a more
254 complicated struct. The library may also store the array descriptor
255 :samp:`{DESC}` when its rank is non-zero.
256
257 For lock types, the value shall only be used for checking the allocation
258 status. Note that for critical blocks, the locking is only required on one
259 image; in the locking statement, the processor shall always pass an
260 image index of one for critical-block lock variables
261 (``CAF_REGTYPE_CRITICAL``). For lock types and critical-block variables,
262 the initial value shall be unlocked (or, respectively, not in critical
263 section) such as the value false; for event types, the initial state should
264 be no event, e.g. zero.
265
266.. index:: Coarray, _gfortran_caf_deregister
267
268.. _gfortran_caf_deregister:
269
270_gfortran_caf_deregister --- Deregistering coarrays
271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
272
273.. function:: void caf_deregister (caf_token_t *token, caf_deregister_t type, int *stat, char *errmsg, size_t errmsg_len)
274
275 Called to free or deregister the memory of a coarray; the processor calls this
276 function for automatic and explicit deallocation. In case of an error, this
277 function shall fail with an error message, unless the :samp:`{STAT}` variable is
278 not null. The library is only expected to free memory it allocated itself
279 during a call to ``_gfortran_caf_register``.
280
281 :param token:
282 the token to free.
283
284 :param type:
285 the type of action to take for the coarray. A
286 ``CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY`` is allowed only for allocatable or
287 pointer components of derived type coarrays. The action only deallocates the
288 local memory without deleting the token.
289
290 :param stat:
291 intent(out) Stores the STAT=; may be NULL
292
293 :param errmsg:
294 intent(out) When an error occurs, this will be set
295 to an error message; may be NULL
296
297 :param errmsg_len:
298 the buffer size of errmsg.
299
300 .. note::
301
302 For nonalloatable coarrays this function is never called. If a cleanup is
303 required, it has to be handled via the finish, stop and error stop functions,
304 and via destructors.
305
306.. index:: Coarray, _gfortran_caf_is_present
307
308.. _gfortran_caf_is_present:
309
310_gfortran_caf_is_present --- Query whether an allocatable or pointer component in a derived type coarray is allocated
311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
312
313.. function:: void _gfortran_caf_is_present (caf_token_t token, int image_index, gfc_reference_t *ref)
314
315 Used to query the coarray library whether an allocatable component in a derived
316 type coarray is allocated on a remote image.
317
318 :param token:
319 An opaque pointer identifying the coarray.
320
321 :param image_index:
322 The ID of the remote image; must be a positive
323 number.
324
325 :param ref:
326 A chain of references to address the allocatable or
327 pointer component in the derived type coarray. The object reference needs to be
328 a scalar or a full array reference, respectively.
329
330.. index:: Coarray, _gfortran_caf_send
331
332.. _gfortran_caf_send:
333
334_gfortran_caf_send --- Sending data from a local image to a remote image
335^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
336
337.. function:: void _gfortran_caf_send (caf_token_t token, size_t offset, int image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector, gfc_descriptor_t *src, int dst_kind, int src_kind, bool may_require_tmp, int *stat)
338
339 Called to send a scalar, an array section or a whole array from a local
340 to a remote image identified by the image_index.
341
342 :param token:
343 intent(in) An opaque pointer identifying the coarray.
344
345 :param offset:
346 intent(in) By which amount of bytes the actual data is
347 shifted compared to the base address of the coarray.
348
349 :param image_index:
350 intent(in) The ID of the remote image; must be a
351 positive number.
352
353 :param dest:
354 intent(in) Array descriptor for the remote image for the
355 bounds and the size. The ``base_addr`` shall not be accessed.
356
357 :param dst_vector:
358 intent(in) If not NULL, it contains the vector
359 subscript of the destination array; the values are relative to the dimension
360 triplet of the dest argument.
361
362 :param src:
363 intent(in) Array descriptor of the local array to be
364 transferred to the remote image
365
366 :param dst_kind:
367 intent(in) Kind of the destination argument
368
369 :param src_kind:
370 intent(in) Kind of the source argument
371
372 :param may_require_tmp:
373 intent(in) The variable is ``false`` when
374 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
375 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
376 :samp:`{dest}` in element wise element order (honoring the stride value) will not
377 lead to wrong results. Otherwise, the value is ``true``.
378
379 :param stat:
380 intent(out) when non-NULL give the result of the
381 operation, i.e., zero on success and non-zero on error. When NULL and an error
382 occurs, then an error message is printed and the program is terminated.
383
384 .. note::
385
386 It is permitted to have :samp:`{image_index}` equal the current image; the memory
387 of the send-to and the send-from might (partially) overlap in that case. The
388 implementation has to take care that it handles this case, e.g. using
389 ``memmove`` which handles (partially) overlapping memory. If
390 :samp:`{may_require_tmp}` is true, the library might additionally create a
391 temporary variable, unless additional checks show that this is not required
392 (e.g. because walking backward is possible or because both arrays are
393 contiguous and ``memmove`` takes care of overlap issues).
394
395 Note that the assignment of a scalar to an array is permitted. In addition,
396 the library has to handle numeric-type conversion and for strings, padding
397 and different character kinds.
398
399.. index:: Coarray, _gfortran_caf_get
400
401.. _gfortran_caf_get:
402
403_gfortran_caf_get --- Getting data from a remote image
404^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
405
406.. function:: void _gfortran_caf_get (caf_token_t token, size_t offset, int image_index, gfc_descriptor_t *src, caf_vector_t *src_vector, gfc_descriptor_t *dest, int src_kind, int dst_kind, bool may_require_tmp, int *stat)
407
408 Called to get an array section or a whole array from a remote,
409 image identified by the image_index.
410
411 :param token:
412 intent(in) An opaque pointer identifying the coarray.
413
414 :param offset:
415 intent(in) By which amount of bytes the actual data is
416 shifted compared to the base address of the coarray.
417
418 :param image_index:
419 intent(in) The ID of the remote image; must be a
420 positive number.
421
422 :param dest:
423 intent(out) Array descriptor of the local array to store
424 the data retrieved from the remote image
425
426 :param src:
427 intent(in) Array descriptor for the remote image for the
428 bounds and the size. The ``base_addr`` shall not be accessed.
429
430 :param src_vector:
431 intent(in) If not NULL, it contains the vector
432 subscript of the source array; the values are relative to the dimension
433 triplet of the :samp:`{src}` argument.
434
435 :param dst_kind:
436 intent(in) Kind of the destination argument
437
438 :param src_kind:
439 intent(in) Kind of the source argument
440
441 :param may_require_tmp:
442 intent(in) The variable is ``false`` when
443 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
444 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
445 :samp:`{dest}` in element wise element order (honoring the stride value) will not
446 lead to wrong results. Otherwise, the value is ``true``.
447
448 :param stat:
449 intent(out) When non-NULL give the result of the
450 operation, i.e., zero on success and non-zero on error. When NULL and an error
451 occurs, then an error message is printed and the program is terminated.
452
453 .. note::
454
455 It is permitted to have :samp:`{image_index}` equal the current image; the memory of
456 the send-to and the send-from might (partially) overlap in that case. The
457 implementation has to take care that it handles this case, e.g. using
458 ``memmove`` which handles (partially) overlapping memory. If
459 :samp:`{may_require_tmp}` is true, the library might additionally create a
460 temporary variable, unless additional checks show that this is not required
461 (e.g. because walking backward is possible or because both arrays are
462 contiguous and ``memmove`` takes care of overlap issues).
463
464 Note that the library has to handle numeric-type conversion and for strings,
465 padding and different character kinds.
466
467.. index:: Coarray, _gfortran_caf_sendget
468
469.. _gfortran_caf_sendget:
470
471_gfortran_caf_sendget --- Sending data between remote images
472^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
473
474.. function:: void _gfortran_caf_sendget (caf_token_t dst_token, size_t dst_offset, int dst_image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector, caf_token_t src_token, size_t src_offset, int src_image_index, gfc_descriptor_t *src, caf_vector_t *src_vector, int dst_kind, int src_kind, bool may_require_tmp, int *stat)
475
476 Called to send a scalar, an array section or a whole array from a remote image
477 identified by the :samp:`{src_image_index}` to a remote image identified by the
478 :samp:`{dst_image_index}`.
479
480 :param dst_token:
481 intent(in) An opaque pointer identifying the
482 destination coarray.
483
484 :param dst_offset:
485 intent(in) By which amount of bytes the actual data
486 is shifted compared to the base address of the destination coarray.
487
488 :param dst_image_index:
489 intent(in) The ID of the destination remote
490 image; must be a positive number.
491
492 :param dest:
493 intent(in) Array descriptor for the destination
494 remote image for the bounds and the size. The ``base_addr`` shall not be
495 accessed.
496
497 :param dst_vector:
498 intent(int) If not NULL, it contains the vector
499 subscript of the destination array; the values are relative to the dimension
500 triplet of the :samp:`{dest}` argument.
501
502 :param src_token:
503 intent(in) An opaque pointer identifying the source
504 coarray.
505
506 :param src_offset:
507 intent(in) By which amount of bytes the actual data
508 is shifted compared to the base address of the source coarray.
509
510 :param src_image_index:
511 intent(in) The ID of the source remote image;
512 must be a positive number.
513
514 :param src:
515 intent(in) Array descriptor of the local array to be
516 transferred to the remote image.
517
518 :param src_vector:
519 intent(in) Array descriptor of the local array to
520 be transferred to the remote image
521
522 :param dst_kind:
523 intent(in) Kind of the destination argument
524
525 :param src_kind:
526 intent(in) Kind of the source argument
527
528 :param may_require_tmp:
529 intent(in) The variable is ``false`` when
530 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
531 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
532 :samp:`{dest}` in element wise element order (honoring the stride value) will not
533 lead to wrong results. Otherwise, the value is ``true``.
534
535 :param stat:
536 intent(out) when non-NULL give the result of the
537 operation, i.e., zero on success and non-zero on error. When NULL and an error
538 occurs, then an error message is printed and the program is terminated.
539
540 .. note::
541
542 It is permitted to have the same image index for both :samp:`{src_image_index}` and
543 :samp:`{dst_image_index}` ; the memory of the send-to and the send-from might
544 (partially) overlap in that case. The implementation has to take care that it
545 handles this case, e.g. using ``memmove`` which handles (partially)
546 overlapping memory. If :samp:`{may_require_tmp}` is true, the library
547 might additionally create a temporary variable, unless additional checks show
548 that this is not required (e.g. because walking backward is possible or because
549 both arrays are contiguous and ``memmove`` takes care of overlap issues).
550
551 Note that the assignment of a scalar to an array is permitted. In addition,
552 the library has to handle numeric-type conversion and for strings, padding and
553 different character kinds.
554
555.. index:: Coarray, _gfortran_caf_send_by_ref
556
557.. _gfortran_caf_send_by_ref:
558
559_gfortran_caf_send_by_ref --- Sending data from a local image to a remote image with enhanced referencing options
560^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
561
562.. function:: void _gfortran_caf_send_by_ref (caf_token_t token, int image_index, gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind, int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat, int dst_type)
563
564 Called to send a scalar, an array section or a whole array from a local to a
565 remote image identified by the :samp:`{image_index}`.
566
567 :param token:
568 intent(in) An opaque pointer identifying the coarray.
569
570 :param image_index:
571 intent(in) The ID of the remote image; must be a
572 positive number.
573
574 :param src:
575 intent(in) Array descriptor of the local array to be
576 transferred to the remote image
577
578 :param refs:
579 intent(in) The references on the remote array to store
580 the data given by src. Guaranteed to have at least one entry.
581
582 :param dst_kind:
583 intent(in) Kind of the destination argument
584
585 :param src_kind:
586 intent(in) Kind of the source argument
587
588 :param may_require_tmp:
589 intent(in) The variable is ``false`` when
590 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
591 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
592 :samp:`{dest}` in element wise element order (honoring the stride value) will not
593 lead to wrong results. Otherwise, the value is ``true``.
594
595 :param dst_reallocatable:
596 intent(in) Set when the destination is of
597 allocatable or pointer type and the refs will allow reallocation, i.e., the ref
598 is a full array or component ref.
599
600 :param stat:
601 intent(out) When non- ``NULL`` give the result of the
602 operation, i.e., zero on success and non-zero on error. When ``NULL`` and
603 an error occurs, then an error message is printed and the program is terminated.
604
605 :param dst_type:
606 intent(in) Give the type of the destination. When
607 the destination is not an array, than the precise type, e.g. of a component in
608 a derived type, is not known, but provided here.
609
610 .. note::
611
612 It is permitted to have :samp:`{image_index}` equal the current image; the memory of
613 the send-to and the send-from might (partially) overlap in that case. The
614 implementation has to take care that it handles this case, e.g. using
615 ``memmove`` which handles (partially) overlapping memory. If
616 :samp:`{may_require_tmp}` is true, the library might additionally create a
617 temporary variable, unless additional checks show that this is not required
618 (e.g. because walking backward is possible or because both arrays are
619 contiguous and ``memmove`` takes care of overlap issues).
620
621 Note that the assignment of a scalar to an array is permitted. In addition,
622 the library has to handle numeric-type conversion and for strings, padding
623 and different character kinds.
624
625 Because of the more complicated references possible some operations may be
626 unsupported by certain libraries. The library is expected to issue a precise
627 error message why the operation is not permitted.
628
629.. index:: Coarray, _gfortran_caf_get_by_ref
630
631.. _gfortran_caf_get_by_ref:
632
633_gfortran_caf_get_by_ref --- Getting data from a remote image using enhanced references
634^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
635
636.. function:: void _gfortran_caf_get_by_ref (caf_token_t token, int image_index, caf_reference_t *refs, gfc_descriptor_t *dst, int dst_kind, int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat, int src_type)
637
638 Called to get a scalar, an array section or a whole array from a remote image
639 identified by the :samp:`{image_index}`.
640
641 :param token:
642 intent(in) An opaque pointer identifying the coarray.
643
644 :param image_index:
645 intent(in) The ID of the remote image; must be a
646 positive number.
647
648 :param refs:
649 intent(in) The references to apply to the remote structure
650 to get the data.
651
652 :param dst:
653 intent(in) Array descriptor of the local array to store
654 the data transferred from the remote image. May be reallocated where needed
655 and when :samp:`{DST_REALLOCATABLE}` allows it.
656
657 :param dst_kind:
658 intent(in) Kind of the destination argument
659
660 :param src_kind:
661 intent(in) Kind of the source argument
662
663 :param may_require_tmp:
664 intent(in) The variable is ``false`` when
665 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
666 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
667 :samp:`{dest}` in element wise element order (honoring the stride value) will not
668 lead to wrong results. Otherwise, the value is ``true``.
669
670 :param dst_reallocatable:
671 intent(in) Set when :samp:`{DST}` is of
672 allocatable or pointer type and its refs allow reallocation, i.e., the full
673 array or a component is referenced.
674
675 :param stat:
676 intent(out) When non- ``NULL`` give the result of the
677 operation, i.e., zero on success and non-zero on error. When ``NULL`` and an
678 error occurs, then an error message is printed and the program is terminated.
679
680 :param src_type:
681 intent(in) Give the type of the source. When the
682 source is not an array, than the precise type, e.g. of a component in a
683 derived type, is not known, but provided here.
684
685 .. note::
686
687 It is permitted to have ``image_index`` equal the current image; the memory
688 of the send-to and the send-from might (partially) overlap in that case. The
689 implementation has to take care that it handles this case, e.g. using
690 ``memmove`` which handles (partially) overlapping memory. If
691 :samp:`{may_require_tmp}` is true, the library might additionally create a
692 temporary variable, unless additional checks show that this is not required
693 (e.g. because walking backward is possible or because both arrays are
694 contiguous and ``memmove`` takes care of overlap issues).
695
696 Note that the library has to handle numeric-type conversion and for strings,
697 padding and different character kinds.
698
699 Because of the more complicated references possible some operations may be
700 unsupported by certain libraries. The library is expected to issue a precise
701 error message why the operation is not permitted.
702
703.. index:: Coarray, _gfortran_caf_sendget_by_ref
704
705.. _gfortran_caf_sendget_by_ref:
706
707_gfortran_caf_sendget_by_ref --- Sending data between remote images using enhanced references on both sides
708^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
709
710.. function:: void _gfortran_caf_sendget_by_ref (caf_token_t dst_token, int dst_image_index, caf_reference_t *dst_refs, caf_token_t src_token, int src_image_index, caf_reference_t *src_refs, int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat, int *src_stat, int dst_type, int src_type)
711
712 Called to send a scalar, an array section or a whole array from a remote image
713 identified by the :samp:`{src_image_index}` to a remote image identified by the
714 :samp:`{dst_image_index}`.
715
716 :param dst_token:
717 intent(in) An opaque pointer identifying the
718 destination coarray.
719
720 :param dst_image_index:
721 intent(in) The ID of the destination remote
722 image; must be a positive number.
723
724 :param dst_refs:
725 intent(in) The references on the remote array to store
726 the data given by the source. Guaranteed to have at least one entry.
727
728 :param src_token:
729 intent(in) An opaque pointer identifying the source
730 coarray.
731
732 :param src_image_index:
733 intent(in) The ID of the source remote image;
734 must be a positive number.
735
736 :param src_refs:
737 intent(in) The references to apply to the remote
738 structure to get the data.
739
740 :param dst_kind:
741 intent(in) Kind of the destination argument
742
743 :param src_kind:
744 intent(in) Kind of the source argument
745
746 :param may_require_tmp:
747 intent(in) The variable is ``false`` when
748 it is known at compile time that the :samp:`{dest}` and :samp:`{src}` either cannot
749 overlap or overlap (fully or partially) such that walking :samp:`{src}` and
750 :samp:`{dest}` in element wise element order (honoring the stride value) will not
751 lead to wrong results. Otherwise, the value is ``true``.
752
753 :param dst_stat:
754 intent(out) when non- ``NULL`` give the result of
755 the send-operation, i.e., zero on success and non-zero on error. When
756 ``NULL`` and an error occurs, then an error message is printed and the
757 program is terminated.
758
759 :param src_stat:
760 intent(out) When non- ``NULL`` give the result of
761 the get-operation, i.e., zero on success and non-zero on error. When
762 ``NULL`` and an error occurs, then an error message is printed and the
763 program is terminated.
764
765 :param dst_type:
766 intent(in) Give the type of the destination. When
767 the destination is not an array, than the precise type, e.g. of a component in
768 a derived type, is not known, but provided here.
769
770 :param src_type:
771 intent(in) Give the type of the source. When the
772 source is not an array, than the precise type, e.g. of a component in a
773 derived type, is not known, but provided here.
774
775 .. note::
776
777 It is permitted to have the same image index for both :samp:`{src_image_index}` and
778 :samp:`{dst_image_index}` ; the memory of the send-to and the send-from might
779 (partially) overlap in that case. The implementation has to take care that it
780 handles this case, e.g. using ``memmove`` which handles (partially)
781 overlapping memory. If :samp:`{may_require_tmp}` is true, the library
782 might additionally create a temporary variable, unless additional checks show
783 that this is not required (e.g. because walking backward is possible or because
784 both arrays are contiguous and ``memmove`` takes care of overlap issues).
785
786 Note that the assignment of a scalar to an array is permitted. In addition,
787 the library has to handle numeric-type conversion and for strings, padding and
788 different character kinds.
789
790 Because of the more complicated references possible some operations may be
791 unsupported by certain libraries. The library is expected to issue a precise
792 error message why the operation is not permitted.
793
794.. index:: Coarray, _gfortran_caf_lock
795
796.. _gfortran_caf_lock:
797
798_gfortran_caf_lock --- Locking a lock variable
799^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
800
801.. function:: void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index, int *acquired_lock, int *stat, char *errmsg, size_t errmsg_len)
802
803 Acquire a lock on the given image on a scalar locking variable or for the
804 given array element for an array-valued variable. If the :samp:`{acquired_lock}`
805 is ``NULL``, the function returns after having obtained the lock. If it is
806 non- ``NULL``, then :samp:`{acquired_lock}` is assigned the value true (one) when
807 the lock could be obtained and false (zero) otherwise. Locking a lock variable
808 which has already been locked by the same image is an error.
809
810 :param token:
811 intent(in) An opaque pointer identifying the coarray.
812
813 :param index:
814 intent(in) Array index; first array index is 0. For
815 scalars, it is always 0.
816
817 :param image_index:
818 intent(in) The ID of the remote image; must be a
819 positive number.
820
821 :param acquired_lock:
822 intent(out) If not NULL, it returns whether lock
823 could be obtained.
824
825 :param stat:
826 intent(out) Stores the STAT=; may be NULL.
827
828 :param errmsg:
829 intent(out) When an error occurs, this will be set to
830 an error message; may be NULL.
831
832 :param errmsg_len:
833 intent(in) the buffer size of errmsg
834
835 .. note::
836
837 This function is also called for critical blocks; for those, the array index
838 is always zero and the image index is one. Libraries are permitted to use other
839 images for critical-block locking variables.
840
841.. index:: Coarray, _gfortran_caf_unlock
842
843.. _gfortran_caf_unlock:
844
845_gfortran_caf_lock --- Unlocking a lock variable
846^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
847
848.. function:: void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index, int *stat, char *errmsg, size_t errmsg_len)
849
850 Release a lock on the given image on a scalar locking variable or for the
851 given array element for an array-valued variable. Unlocking a lock variable
852 which is unlocked or has been locked by a different image is an error.
853
854 :param token:
855 intent(in) An opaque pointer identifying the coarray.
856
857 :param index:
858 intent(in) Array index; first array index is 0. For
859 scalars, it is always 0.
860
861 :param image_index:
862 intent(in) The ID of the remote image; must be a
863 positive number.
864
865 :param stat:
866 intent(out) For allocatable coarrays, stores the STAT=;
867 may be NULL.
868
869 :param errmsg:
870 intent(out) When an error occurs, this will be set to
871 an error message; may be NULL.
872
873 :param errmsg_len:
874 intent(in) the buffer size of errmsg
875
876 .. note::
877
878 This function is also called for critical block; for those, the array index
879 is always zero and the image index is one. Libraries are permitted to use other
880 images for critical-block locking variables.
881
882.. index:: Coarray, _gfortran_caf_event_post
883
884.. _gfortran_caf_event_post:
885
886_gfortran_caf_event_post --- Post an event
887^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
888
889.. function:: void _gfortran_caf_event_post (caf_token_t token, size_t index, int image_index, int *stat, char *errmsg, size_t errmsg_len)
890
891 Increment the event count of the specified event variable.
892
893 :param token:
894 intent(in) An opaque pointer identifying the coarray.
895
896 :param index:
897 intent(in) Array index; first array index is 0. For
898 scalars, it is always 0.
899
900 :param image_index:
901 intent(in) The ID of the remote image; must be a
902 positive number; zero indicates the current image, when accessed noncoindexed.
903
904 :param stat:
905 intent(out) Stores the STAT=; may be NULL.
906
907 :param errmsg:
908 intent(out) When an error occurs, this will be set to
909 an error message; may be NULL.
910
911 :param errmsg_len:
912 intent(in) the buffer size of errmsg
913
914 .. note::
915
916 This acts like an atomic add of one to the remote image's event variable.
917 The statement is an image-control statement but does not imply sync memory.
918 Still, all preceeding push communications of this image to the specified
919 remote image have to be completed before ``event_wait`` on the remote
920 image returns.
921
922.. index:: Coarray, _gfortran_caf_event_wait
923
924.. _gfortran_caf_event_wait:
925
926_gfortran_caf_event_wait --- Wait that an event occurred
927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
928
929.. function:: void _gfortran_caf_event_wait (caf_token_t token, size_t index, int until_count, int *stat, char *errmsg, size_t errmsg_len)
930
931 Wait until the event count has reached at least the specified
932 :samp:`{until_count}` ; if so, atomically decrement the event variable by this
933 amount and return.
934
935 :param token:
936 intent(in) An opaque pointer identifying the coarray.
937
938 :param index:
939 intent(in) Array index; first array index is 0. For
940 scalars, it is always 0.
941
942 :param until_count:
943 intent(in) The number of events which have to be
944 available before the function returns.
945
946 :param stat:
947 intent(out) Stores the STAT=; may be NULL.
948
949 :param errmsg:
950 intent(out) When an error occurs, this will be set to
951 an error message; may be NULL.
952
953 :param errmsg_len:
954 intent(in) the buffer size of errmsg
955
956 .. note::
957
958 This function only operates on a local coarray. It acts like a loop checking
959 atomically the value of the event variable, breaking if the value is greater
960 or equal the requested number of counts. Before the function returns, the
961 event variable has to be decremented by the requested :samp:`{until_count}` value.
962 A possible implementation would be a busy loop for a certain number of spins
963 (possibly depending on the number of threads relative to the number of available
964 cores) followed by another waiting strategy such as a sleeping wait (possibly
965 with an increasing number of sleep time) or, if possible, a futex wait.
966
967 The statement is an image-control statement but does not imply sync memory.
968 Still, all preceeding push communications of this image to the specified
969 remote image have to be completed before ``event_wait`` on the remote
970 image returns.
971
972.. index:: Coarray, _gfortran_caf_event_query
973
974.. _gfortran_caf_event_query:
975
976_gfortran_caf_event_query --- Query event count
977^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
978
979.. function:: void _gfortran_caf_event_query (caf_token_t token, size_t index, int image_index, int *count, int *stat)
980
981 Return the event count of the specified event variable.
982
983 :param token:
984 intent(in) An opaque pointer identifying the coarray.
985
986 :param index:
987 intent(in) Array index; first array index is 0. For
988 scalars, it is always 0.
989
990 :param image_index:
991 intent(in) The ID of the remote image; must be a
992 positive number; zero indicates the current image when accessed noncoindexed.
993
994 :param count:
995 intent(out) The number of events currently posted to
996 the event variable.
997
998 :param stat:
999 intent(out) Stores the STAT=; may be NULL.
1000
1001 .. note::
1002
1003 The typical use is to check the local event variable to only call
1004 ``event_wait`` when the data is available. However, a coindexed variable
1005 is permitted; there is no ordering or synchronization implied. It acts like
1006 an atomic fetch of the value of the event variable.
1007
1008.. index:: Coarray, _gfortran_caf_sync_all
1009
1010.. _gfortran_caf_sync_all:
1011
1012_gfortran_caf_sync_all --- All-image barrier
1013^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1014
1015.. function:: void _gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len)
1016
1017 Synchronization of all images in the current team; the program only continues
1018 on a given image after this function has been called on all images of the
1019 current team. Additionally, it ensures that all pending data transfers of
1020 previous segment have completed.
1021
1022 :param stat:
1023 intent(out) Stores the status STAT= and may be NULL.
1024
1025 :param errmsg:
1026 intent(out) When an error occurs, this will be set to
1027 an error message; may be NULL.
1028
1029 :param errmsg_len:
1030 intent(in) the buffer size of errmsg
1031
1032.. index:: Coarray, _gfortran_caf_sync_images
1033
1034.. _gfortran_caf_sync_images:
1035
1036_gfortran_caf_sync_images --- Barrier for selected images
1037^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1038
1039.. function:: void _gfortran_caf_sync_images (int count, int images[], int *stat, char *errmsg, size_t errmsg_len)
1040
1041 Synchronization between the specified images; the program only continues on a
1042 given image after this function has been called on all images specified for
1043 that image. Note that one image can wait for all other images in the current
1044 team (e.g. via ``sync images(*)``) while those only wait for that specific
1045 image. Additionally, ``sync images`` ensures that all pending data
1046 transfers of previous segments have completed.
1047
1048 :param count:
1049 intent(in) The number of images which are provided in
1050 the next argument. For a zero-sized array, the value is zero. For
1051 ``sync images (*)``, the value is -1.
1052
1053 :param images:
1054 intent(in) An array with the images provided by the
1055 user. If :samp:`{count}` is zero, a NULL pointer is passed.
1056
1057 :param stat:
1058 intent(out) Stores the status STAT= and may be NULL.
1059
1060 :param errmsg:
1061 intent(out) When an error occurs, this will be set to
1062 an error message; may be NULL.
1063
1064 :param errmsg_len:
1065 intent(in) the buffer size of errmsg
1066
1067.. index:: Coarray, _gfortran_caf_sync_memory
1068
1069.. _gfortran_caf_sync_memory:
1070
1071_gfortran_caf_sync_memory --- Wait for completion of segment-memory operations
1072^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1073
1074.. function:: void _gfortran_caf_sync_memory (int *stat, char *errmsg, size_t errmsg_len)
1075
1076 Acts as optimization barrier between different segments. It also ensures that
1077 all pending memory operations of this image have been completed.
1078
1079 :param stat:
1080 intent(out) Stores the status STAT= and may be NULL.
1081
1082 :param errmsg:
1083 intent(out) When an error occurs, this will be set to
1084 an error message; may be NULL.
1085
1086 :param errmsg_len:
1087 intent(in) the buffer size of errmsg
1088
1089 .. note::
1090
1091 A simple implementation could be
1092 ``__asm__ __volatile__ ("":::"memory")`` to prevent code movements.
1093
1094.. index:: Coarray, _gfortran_caf_error_stop
1095
1096.. _gfortran_caf_error_stop:
1097
1098_gfortran_caf_error_stop --- Error termination with exit code
1099^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1100
1101.. function:: void _gfortran_caf_error_stop (int error)
1102
1103 Invoked for an ``ERROR STOP`` statement which has an integer argument. The
1104 function should terminate the program with the specified exit code.
1105
1106 :param error:
1107 intent(in) The exit status to be used.
1108
1109.. index:: Coarray, _gfortran_caf_error_stop_str
1110
1111.. _gfortran_caf_error_stop_str:
1112
1113_gfortran_caf_error_stop_str --- Error termination with string
1114^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1115
1116.. function:: void _gfortran_caf_error_stop (const char *string, size_t len)
1117
1118 Invoked for an ``ERROR STOP`` statement which has a string as argument. The
1119 function should terminate the program with a nonzero-exit code.
1120
1121 :param string:
1122 intent(in) the error message (not zero terminated)
1123
1124 :param len:
1125 intent(in) the length of the string
1126
1127.. index:: Coarray, _gfortran_caf_fail_image
1128
1129.. _gfortran_caf_fail_image:
1130
1131_gfortran_caf_fail_image --- Mark the image failed and end its execution
1132^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1133
1134.. function:: void _gfortran_caf_fail_image ()
1135
1136 Invoked for an ``FAIL IMAGE`` statement. The function should terminate the
1137 current image.
1138
1139 .. note::
1140
1141 This function follows TS18508.
1142
1143.. index:: Coarray, _gfortran_caf_atomic_define
1144
1145.. _gfortran_caf_atomic_define:
1146
1147_gfortran_caf_atomic_define --- Atomic variable assignment
1148^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1149
1150.. function:: void _gfortran_caf_atomic_define (caf_token_t token, size_t offset, int image_index, void *value, int *stat, int type, int kind)
1151
1152 Assign atomically a value to an integer or logical variable.
1153
1154 :param token:
1155 intent(in) An opaque pointer identifying the coarray.
1156
1157 :param offset:
1158 intent(in) By which amount of bytes the actual data is
1159 shifted compared to the base address of the coarray.
1160
1161 :param image_index:
1162 intent(in) The ID of the remote image; must be a
1163 positive number; zero indicates the current image when used noncoindexed.
1164
1165 :param value:
1166 intent(in) the value to be assigned, passed by reference
1167
1168 :param stat:
1169 intent(out) Stores the status STAT= and may be NULL.
1170
1171 :param type:
1172 intent(in) The data type, i.e. ``BT_INTEGER`` (1) or
1173 ``BT_LOGICAL`` (2).
1174
1175 :param kind:
1176 intent(in) The kind value (only 4; always ``int``)
1177
1178.. index:: Coarray, _gfortran_caf_atomic_ref
1179
1180.. _gfortran_caf_atomic_ref:
1181
1182_gfortran_caf_atomic_ref --- Atomic variable reference
1183^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1184
1185.. function:: void _gfortran_caf_atomic_ref (caf_token_t token, size_t offset, int image_index, void *value, int *stat, int type, int kind)
1186
1187 Reference atomically a value of a kind-4 integer or logical variable.
1188
1189 :param token:
1190 intent(in) An opaque pointer identifying the coarray.
1191
1192 :param offset:
1193 intent(in) By which amount of bytes the actual data is
1194 shifted compared to the base address of the coarray.
1195
1196 :param image_index:
1197 intent(in) The ID of the remote image; must be a
1198 positive number; zero indicates the current image when used noncoindexed.
1199
1200 :param value:
1201 intent(out) The variable assigned the atomically
1202 referenced variable.
1203
1204 :param stat:
1205 intent(out) Stores the status STAT= and may be NULL.
1206
1207 :param type:
1208 the data type, i.e. ``BT_INTEGER`` (1) or
1209 ``BT_LOGICAL`` (2).
1210
1211 :param kind:
1212 The kind value (only 4; always ``int``)
1213
1214.. index:: Coarray, _gfortran_caf_atomic_cas
1215
1216.. _gfortran_caf_atomic_cas:
1217
1218_gfortran_caf_atomic_cas --- Atomic compare and swap
1219^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1220
1221.. function:: void _gfortran_caf_atomic_cas (caf_token_t token, size_t offset, int image_index, void *old, void *compare, void *new_val, int *stat, int type, int kind)
1222
1223 Atomic compare and swap of a kind-4 integer or logical variable. Assigns
1224 atomically the specified value to the atomic variable, if the latter has
1225 the value specified by the passed condition value.
1226
1227 :param token:
1228 intent(in) An opaque pointer identifying the coarray.
1229
1230 :param offset:
1231 intent(in) By which amount of bytes the actual data is
1232 shifted compared to the base address of the coarray.
1233
1234 :param image_index:
1235 intent(in) The ID of the remote image; must be a
1236 positive number; zero indicates the current image when used noncoindexed.
1237
1238 :param old:
1239 intent(out) The value which the atomic variable had
1240 just before the cas operation.
1241
1242 :param compare:
1243 intent(in) The value used for comparision.
1244
1245 :param new_val:
1246 intent(in) The new value for the atomic variable,
1247 assigned to the atomic variable, if ``compare`` equals the value of the
1248 atomic variable.
1249
1250 :param stat:
1251 intent(out) Stores the status STAT= and may be NULL.
1252
1253 :param type:
1254 intent(in) the data type, i.e. ``BT_INTEGER`` (1) or
1255 ``BT_LOGICAL`` (2).
1256
1257 :param kind:
1258 intent(in) The kind value (only 4; always ``int``)
1259
1260.. index:: Coarray, _gfortran_caf_atomic_op
1261
1262.. _gfortran_caf_atomic_op:
1263
1264_gfortran_caf_atomic_op --- Atomic operation
1265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1266
1267.. function:: void _gfortran_caf_atomic_op (int op, caf_token_t token, size_t offset, int image_index, void *value, void *old, int *stat, int type, int kind)
1268
1269 Apply an operation atomically to an atomic integer or logical variable.
1270 After the operation, :samp:`{old}` contains the value just before the operation,
1271 which, respectively, adds (GFC_CAF_ATOMIC_ADD) atomically the ``value`` to
1272 the atomic integer variable or does a bitwise AND, OR or exclusive OR
1273 between the atomic variable and :samp:`{value}` ; the result is then stored in the
1274 atomic variable.
1275
1276 :param op:
1277 intent(in) the operation to be performed; possible values
1278 ``GFC_CAF_ATOMIC_ADD`` (1), ``GFC_CAF_ATOMIC_AND`` (2),
1279 ``GFC_CAF_ATOMIC_OR`` (3), ``GFC_CAF_ATOMIC_XOR`` (4).
1280
1281 :param token:
1282 intent(in) An opaque pointer identifying the coarray.
1283
1284 :param offset:
1285 intent(in) By which amount of bytes the actual data is
1286 shifted compared to the base address of the coarray.
1287
1288 :param image_index:
1289 intent(in) The ID of the remote image; must be a
1290 positive number; zero indicates the current image when used noncoindexed.
1291
1292 :param old:
1293 intent(out) The value which the atomic variable had
1294 just before the atomic operation.
1295
1296 :param val:
1297 intent(in) The new value for the atomic variable,
1298 assigned to the atomic variable, if ``compare`` equals the value of the
1299 atomic variable.
1300
1301 :param stat:
1302 intent(out) Stores the status STAT= and may be NULL.
1303
1304 :param type:
1305 intent(in) the data type, i.e. ``BT_INTEGER`` (1) or
1306 ``BT_LOGICAL`` (2)
1307
1308 :param kind:
1309 intent(in) the kind value (only 4; always ``int``)
1310
1311.. index:: Coarray, _gfortran_caf_co_broadcast
1312
1313.. _gfortran_caf_co_broadcast:
1314
1315_gfortran_caf_co_broadcast --- Sending data to all images
1316^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1317
1318.. function:: void _gfortran_caf_co_broadcast (gfc_descriptor_t *a, int source_image, int *stat, char *errmsg, size_t errmsg_len)
1319
1320 Distribute a value from a given image to all other images in the team. Has to
1321 be called collectively.
1322
1323 :param a:
1324 intent(inout) An array descriptor with the data to be
1325 broadcasted (on :samp:`{source_image}`) or to be received (other images).
1326
1327 :param source_image:
1328 intent(in) The ID of the image from which the
1329 data should be broadcasted.
1330
1331 :param stat:
1332 intent(out) Stores the status STAT= and may be NULL.
1333
1334 :param errmsg:
1335 intent(out) When an error occurs, this will be set to
1336 an error message; may be NULL.
1337
1338 :param errmsg_len:
1339 intent(in) the buffer size of errmsg.
1340
1341.. index:: Coarray, _gfortran_caf_co_max
1342
1343.. _gfortran_caf_co_max:
1344
1345_gfortran_caf_co_max --- Collective maximum reduction
1346^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1347
1348.. function:: void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image, int *stat, char *errmsg, int a_len, size_t errmsg_len)
1349
1350 Calculates for each array element of the variable :samp:`{a}` the maximum
1351 value for that element in the current team; if :samp:`{result_image}` has the
1352 value 0, the result shall be stored on all images, otherwise, only on the
1353 specified image. This function operates on numeric values and character
1354 strings.
1355
1356 :param a:
1357 intent(inout) An array descriptor for the data to be
1358 processed. On the destination image(s) the result overwrites the old content.
1359
1360 :param result_image:
1361 intent(in) The ID of the image to which the
1362 reduced value should be copied to; if zero, it has to be copied to all images.
1363
1364 :param stat:
1365 intent(out) Stores the status STAT= and may be NULL.
1366
1367 :param errmsg:
1368 intent(out) When an error occurs, this will be set to
1369 an error message; may be NULL.
1370
1371 :param a_len:
1372 intent(in) the string length of argument :samp:`{a}`
1373
1374 :param errmsg_len:
1375 intent(in) the buffer size of errmsg
1376
1377 .. note::
1378
1379 If :samp:`{result_image}` is nonzero, the data in the array descriptor :samp:`{a}` on
1380 all images except of the specified one become undefined; hence, the library may
1381 make use of this.
1382
1383.. index:: Coarray, _gfortran_caf_co_min
1384
1385.. _gfortran_caf_co_min:
1386
1387_gfortran_caf_co_min --- Collective minimum reduction
1388^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1389
1390.. function:: void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image, int *stat, char *errmsg, int a_len, size_t errmsg_len)
1391
1392 Calculates for each array element of the variable :samp:`{a}` the minimum
1393 value for that element in the current team; if :samp:`{result_image}` has the
1394 value 0, the result shall be stored on all images, otherwise, only on the
1395 specified image. This function operates on numeric values and character
1396 strings.
1397
1398 :param a:
1399 intent(inout) An array descriptor for the data to be
1400 processed. On the destination image(s) the result overwrites the old content.
1401
1402 :param result_image:
1403 intent(in) The ID of the image to which the
1404 reduced value should be copied to; if zero, it has to be copied to all images.
1405
1406 :param stat:
1407 intent(out) Stores the status STAT= and may be NULL.
1408
1409 :param errmsg:
1410 intent(out) When an error occurs, this will be set to
1411 an error message; may be NULL.
1412
1413 :param a_len:
1414 intent(in) the string length of argument :samp:`{a}`
1415
1416 :param errmsg_len:
1417 intent(in) the buffer size of errmsg
1418
1419 .. note::
1420
1421 If :samp:`{result_image}` is nonzero, the data in the array descriptor :samp:`{a}` on
1422 all images except of the specified one become undefined; hence, the library may
1423 make use of this.
1424
1425.. index:: Coarray, _gfortran_caf_co_sum
1426
1427.. _gfortran_caf_co_sum:
1428
1429_gfortran_caf_co_sum --- Collective summing reduction
1430^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1431
1432.. function:: void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image, int *stat, char *errmsg, size_t errmsg_len)
1433
1434 Calculates for each array element of the variable :samp:`{a}` the sum of all
1435 values for that element in the current team; if :samp:`{result_image}` has the
1436 value 0, the result shall be stored on all images, otherwise, only on the
1437 specified image. This function operates on numeric values only.
1438
1439 :param a:
1440 intent(inout) An array descriptor with the data to be
1441 processed. On the destination image(s) the result overwrites the old content.
1442
1443 :param result_image:
1444 intent(in) The ID of the image to which the
1445 reduced value should be copied to; if zero, it has to be copied to all images.
1446
1447 :param stat:
1448 intent(out) Stores the status STAT= and may be NULL.
1449
1450 :param errmsg:
1451 intent(out) When an error occurs, this will be set to
1452 an error message; may be NULL.
1453
1454 :param errmsg_len:
1455 intent(in) the buffer size of errmsg
1456
1457 .. note::
1458
1459 If :samp:`{result_image}` is nonzero, the data in the array descriptor :samp:`{a}` on
1460 all images except of the specified one become undefined; hence, the library may
1461 make use of this.
1462
1463.. index:: Coarray, _gfortran_caf_co_reduce
1464
1465.. _gfortran_caf_co_reduce:
1466
1467_gfortran_caf_co_reduce --- Generic collective reduction
1468^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1469
1470.. function:: void _gfortran_caf_co_reduce (gfc_descriptor_t *a, void * (*opr) (void *, void *), int opr_flags, int result_image, int *stat, char *errmsg, int a_len, size_t errmsg_len)
1471
1472 Calculates for each array element of the variable :samp:`{a}` the reduction
1473 value for that element in the current team; if :samp:`{result_image}` has the
1474 value 0, the result shall be stored on all images, otherwise, only on the
1475 specified image. The :samp:`{opr}` is a pure function doing a mathematically
1476 commutative and associative operation.
1477
1478 :param a:
1479 intent(inout) An array descriptor with the data to be
1480 processed. On the destination image(s) the result overwrites the old content.
1481
1482 :param opr:
1483 intent(in) Function pointer to the reduction function
1484
1485 :param opr_flags:
1486 intent(in) Flags regarding the reduction function
1487
1488 :param result_image:
1489 intent(in) The ID of the image to which the
1490 reduced value should be copied to; if zero, it has to be copied to all images.
1491
1492 :param stat:
1493 intent(out) Stores the status STAT= and may be NULL.
1494
1495 :param errmsg:
1496 intent(out) When an error occurs, this will be set to
1497 an error message; may be NULL.
1498
1499 :param a_len:
1500 intent(in) the string length of argument :samp:`{a}`
1501
1502 :param errmsg_len:
1503 intent(in) the buffer size of errmsg
1504
1505 .. note::
1506
1507 If :samp:`{result_image}` is nonzero, the data in the array descriptor :samp:`{a}` on
1508 all images except of the specified one become undefined; hence, the library may
1509 make use of this.
1510
1511 For character arguments, the result is passed as first argument, followed
1512 by the result string length, next come the two string arguments, followed
1513 by the two hidden string length arguments. With C binding, there are no hidden
1514 arguments and by-reference passing and either only a single character is passed
1515 or an array descriptor.
1516
1517.. Intrinsic Procedures
1518 -
1519
1520Some basic guidelines for editing this document:
1521
1522(1) The intrinsic procedures are to be listed in alphabetical order.
1523(2) The generic name is to be used.
1524(3) The specific names are included in the function index and in a
1525 table at the end of the node (See ABS entry).
3ed1b4ce 1526(4) Try to maintain the same style for each entry.