2017-07-18 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libgfortran / caf / libcaf.h
blob24726462e893d451c97c6d20a8358d079ce6e542
1 /* Common declarations for all of GNU Fortran libcaf implementations.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 Contributed by Tobias Burnus <burnus@net-b.de>
5 This file is part of the GNU Fortran Coarray Runtime Library (libcaf).
7 Libcaf is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Libcaf is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef LIBCAF_H
27 #define LIBCAF_H
29 #include <stdbool.h>
30 #include <stddef.h> /* For size_t. */
31 #include <stdint.h> /* For int32_t. */
33 #include "libgfortran.h"
35 #if 0
36 #ifndef __GNUC__
37 #define __attribute__(x)
38 #define likely(x) (x)
39 #define unlikely(x) (x)
40 #else
41 #define likely(x) __builtin_expect(!!(x), 1)
42 #define unlikely(x) __builtin_expect(!!(x), 0)
43 #endif
44 #endif
46 /* Definitions of the Fortran 2008 standard; need to kept in sync with
47 ISO_FORTRAN_ENV, cf. gcc/fortran/libgfortran.h. */
48 typedef enum
50 CAF_STAT_UNLOCKED = 0,
51 CAF_STAT_LOCKED,
52 CAF_STAT_LOCKED_OTHER_IMAGE,
53 CAF_STAT_STOPPED_IMAGE = 6000,
54 CAF_STAT_FAILED_IMAGE = 6001
56 caf_stat_codes_t;
59 /* Describes what type of array we are registerring. Keep in sync with
60 gcc/fortran/trans.h. */
61 typedef enum caf_register_t {
62 CAF_REGTYPE_COARRAY_STATIC,
63 CAF_REGTYPE_COARRAY_ALLOC,
64 CAF_REGTYPE_LOCK_STATIC,
65 CAF_REGTYPE_LOCK_ALLOC,
66 CAF_REGTYPE_CRITICAL,
67 CAF_REGTYPE_EVENT_STATIC,
68 CAF_REGTYPE_EVENT_ALLOC,
69 CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY,
70 CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
72 caf_register_t;
74 /* Describes the action to take on _caf_deregister. Keep in sync with
75 gcc/fortran/trans.h. */
76 typedef enum caf_deregister_t {
77 CAF_DEREGTYPE_COARRAY_DEREGISTER,
78 CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY
80 caf_deregister_t;
82 typedef void* caf_token_t;
83 typedef void * caf_team_t;
84 typedef gfc_array_void gfc_descriptor_t;
86 /* Linked list of static coarrays registered. */
87 typedef struct caf_static_t {
88 caf_token_t token;
89 struct caf_static_t *prev;
91 caf_static_t;
93 /* When there is a vector subscript in this dimension, nvec == 0, otherwise,
94 lower_bound, upper_bound, stride contains the bounds relative to the declared
95 bounds; kind denotes the integer kind of the elements of vector[]. */
96 typedef struct caf_vector_t {
97 size_t nvec;
98 union {
99 struct {
100 void *vector;
101 int kind;
102 } v;
103 struct {
104 ptrdiff_t lower_bound, upper_bound, stride;
105 } triplet;
106 } u;
108 caf_vector_t;
110 typedef enum caf_ref_type_t {
111 /* Reference a component of a derived type, either regular one or an
112 allocatable or pointer type. For regular ones idx in caf_reference_t is
113 set to -1. */
114 CAF_REF_COMPONENT,
115 /* Reference an allocatable array. */
116 CAF_REF_ARRAY,
117 /* Reference a non-allocatable/non-pointer array. */
118 CAF_REF_STATIC_ARRAY
119 } caf_ref_type_t;
121 typedef enum caf_array_ref_t {
122 /* No array ref. This terminates the array ref. */
123 CAF_ARR_REF_NONE = 0,
124 /* Reference array elements given by a vector. Only for this mode
125 caf_reference_t.u.a.dim[i].v is valid. */
126 CAF_ARR_REF_VECTOR,
127 /* A full array ref (:). */
128 CAF_ARR_REF_FULL,
129 /* Reference a range on elements given by start, end and stride. */
130 CAF_ARR_REF_RANGE,
131 /* Only a single item is referenced given in the start member. */
132 CAF_ARR_REF_SINGLE,
133 /* An array ref of the kind (i:), where i is an arbitrary valid index in the
134 array. The index i is given in the start member. */
135 CAF_ARR_REF_OPEN_END,
136 /* An array ref of the kind (:i), where the lower bound of the array ref
137 is given by the remote side. The index i is given in the end member. */
138 CAF_ARR_REF_OPEN_START
139 } caf_array_ref_t;
141 /* References to remote components of a derived type. */
142 typedef struct caf_reference_t {
143 /* A pointer to the next ref or NULL. */
144 struct caf_reference_t *next;
145 /* The type of the reference. */
146 /* caf_ref_type_t, replaced by int to allow specification in fortran FE. */
147 int type;
148 /* The size of an item referenced in bytes. I.e. in an array ref this is
149 the factor to advance the array pointer with to get to the next item.
150 For component refs this gives just the size of the element referenced. */
151 size_t item_size;
152 union {
153 struct {
154 /* The offset (in bytes) of the component in the derived type. */
155 ptrdiff_t offset;
156 /* The offset (in bytes) to the caf_token associated with this
157 component. NULL, when not allocatable/pointer ref. */
158 ptrdiff_t caf_token_offset;
159 } c;
160 struct {
161 /* The mode of the array ref. See CAF_ARR_REF_*. */
162 /* caf_array_ref_t, replaced by unsigend char to allow specification in
163 fortran FE. */
164 unsigned char mode[GFC_MAX_DIMENSIONS];
165 /* The type of a static array. Unset for array's with descriptors. */
166 int static_array_type;
167 /* Subscript refs (s) or vector refs (v). */
168 union {
169 struct {
170 /* The start and end boundary of the ref and the stride. */
171 index_type start, end, stride;
172 } s;
173 struct {
174 /* nvec entries of kind giving the elements to reference. */
175 void *vector;
176 /* The number of entries in vector. */
177 size_t nvec;
178 /* The integer kind used for the elements in vector. */
179 int kind;
180 } v;
181 } dim[GFC_MAX_DIMENSIONS];
182 } a;
183 } u;
184 } caf_reference_t;
186 void _gfortran_caf_init (int *, char ***);
187 void _gfortran_caf_finalize (void);
189 int _gfortran_caf_this_image (int);
190 int _gfortran_caf_num_images (int, int);
192 void _gfortran_caf_register (size_t, caf_register_t, caf_token_t *,
193 gfc_descriptor_t *, int *, char *, int);
194 void _gfortran_caf_deregister (caf_token_t *, caf_deregister_t, int *, char *,
195 int);
197 void _gfortran_caf_sync_all (int *, char *, int);
198 void _gfortran_caf_sync_memory (int *, char *, int);
199 void _gfortran_caf_sync_images (int, int[], int *, char *, int);
201 void _gfortran_caf_stop_numeric (int32_t)
202 __attribute__ ((noreturn));
203 void _gfortran_caf_stop_str (const char *, int32_t)
204 __attribute__ ((noreturn));
205 void _gfortran_caf_error_stop_str (const char *, int32_t)
206 __attribute__ ((noreturn));
207 void _gfortran_caf_error_stop (int32_t) __attribute__ ((noreturn));
208 void _gfortran_caf_fail_image (void) __attribute__ ((noreturn));
210 void _gfortran_caf_co_broadcast (gfc_descriptor_t *, int, int *, char *, int);
211 void _gfortran_caf_co_sum (gfc_descriptor_t *, int, int *, char *, int);
212 void _gfortran_caf_co_min (gfc_descriptor_t *, int, int *, char *, int, int);
213 void _gfortran_caf_co_max (gfc_descriptor_t *, int, int *, char *, int, int);
214 void _gfortran_caf_co_reduce (gfc_descriptor_t *, void* (*) (void *, void*),
215 int, int, int *, char *, int, int);
217 void _gfortran_caf_get (caf_token_t, size_t, int, gfc_descriptor_t *,
218 caf_vector_t *, gfc_descriptor_t *, int, int, bool,
219 int *);
220 void _gfortran_caf_send (caf_token_t, size_t, int, gfc_descriptor_t *,
221 caf_vector_t *, gfc_descriptor_t *, int, int, bool,
222 int *);
223 void _gfortran_caf_sendget (caf_token_t, size_t, int, gfc_descriptor_t *,
224 caf_vector_t *, caf_token_t, size_t, int,
225 gfc_descriptor_t *, caf_vector_t *, int, int, bool);
227 void _gfortran_caf_get_by_ref (caf_token_t token, int image_idx,
228 gfc_descriptor_t *dst, caf_reference_t *refs, int dst_kind,
229 int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat);
230 void _gfortran_caf_send_by_ref (caf_token_t token, int image_index,
231 gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind,
232 int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat);
233 void _gfortran_caf_sendget_by_ref (
234 caf_token_t dst_token, int dst_image_index, caf_reference_t *dst_refs,
235 caf_token_t src_token, int src_image_index, caf_reference_t *src_refs,
236 int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat,
237 int *src_stat);
239 void _gfortran_caf_atomic_define (caf_token_t, size_t, int, void *, int *,
240 int, int);
241 void _gfortran_caf_atomic_ref (caf_token_t, size_t, int, void *, int *,
242 int, int);
243 void _gfortran_caf_atomic_cas (caf_token_t, size_t, int, void *, void *,
244 void *, int *, int, int);
245 void _gfortran_caf_atomic_op (int, caf_token_t, size_t, int, void *, void *,
246 int *, int, int);
248 void _gfortran_caf_lock (caf_token_t, size_t, int, int *, int *, char *, int);
249 void _gfortran_caf_unlock (caf_token_t, size_t, int, int *, char *, int);
250 void _gfortran_caf_event_post (caf_token_t, size_t, int, int *, char *, int);
251 void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, int);
252 void _gfortran_caf_event_query (caf_token_t, size_t, int, int *, int *);
254 void _gfortran_caf_failed_images (gfc_descriptor_t *,
255 caf_team_t * __attribute__ ((unused)), int *);
256 int _gfortran_caf_image_status (int, caf_team_t * __attribute__ ((unused)));
257 void _gfortran_caf_stopped_images (gfc_descriptor_t *,
258 caf_team_t * __attribute__ ((unused)),
259 int *);
261 int _gfortran_caf_is_present (caf_token_t, int, caf_reference_t *);
263 #endif /* LIBCAF_H */