| 1 |
/* Common declarations for all of GNU Fortran libcaf implementations. |
| 2 |
Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Tobias Burnus <[email protected]> |
| 4 |
|
| 5 |
This file is part of the GNU Fortran Coarray Runtime Library (libcaf). |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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. |
| 20 |
|
| 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/>. */ |
| 25 |
|
| 26 |
#ifndef LIBCAF_H |
| 27 |
#define LIBCAF_H |
| 28 |
|
| 29 |
#include <stdbool.h> |
| 30 |
#include <stddef.h> /* For size_t. */ |
| 31 |
|
| 32 |
#include "libgfortran.h" |
| 33 |
|
| 34 |
#if 0 |
| 35 |
#ifndef __GNUC__ |
| 36 |
#define __attribute__(x) |
| 37 |
#define likely(x) (x) |
| 38 |
#define unlikely(x) (x) |
| 39 |
#else |
| 40 |
#define likely(x) __builtin_expect(!!(x), 1) |
| 41 |
#define unlikely(x) __builtin_expect(!!(x), 0) |
| 42 |
#endif |
| 43 |
#endif |
| 44 |
|
| 45 |
/* Definitions of the Fortran 2008 standard; need to kept in sync with |
| 46 |
ISO_FORTRAN_ENV, cf. gcc/fortran/libgfortran.h. */ |
| 47 |
typedef enum |
| 48 |
{ |
| 49 |
CAF_STAT_UNLOCKED = 0, |
| 50 |
CAF_STAT_LOCKED, |
| 51 |
CAF_STAT_LOCKED_OTHER_IMAGE, |
| 52 |
CAF_STAT_STOPPED_IMAGE = 6000, |
| 53 |
CAF_STAT_FAILED_IMAGE = 6001 |
| 54 |
} |
| 55 |
caf_stat_codes_t; |
| 56 |
|
| 57 |
|
| 58 |
/* Describes what type of array we are registerring. Keep in sync with |
| 59 |
gcc/fortran/trans.h. */ |
| 60 |
typedef enum caf_register_t { |
| 61 |
CAF_REGTYPE_COARRAY_STATIC, |
| 62 |
CAF_REGTYPE_COARRAY_ALLOC, |
| 63 |
CAF_REGTYPE_LOCK_STATIC, |
| 64 |
CAF_REGTYPE_LOCK_ALLOC, |
| 65 |
CAF_REGTYPE_CRITICAL, |
| 66 |
CAF_REGTYPE_EVENT_STATIC, |
| 67 |
CAF_REGTYPE_EVENT_ALLOC, |
| 68 |
CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY, |
| 69 |
CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY |
| 70 |
} |
| 71 |
caf_register_t; |
| 72 |
|
| 73 |
/* Describes the action to take on _caf_deregister. Keep in sync with |
| 74 |
gcc/fortran/trans.h. */ |
| 75 |
typedef enum caf_deregister_t { |
| 76 |
CAF_DEREGTYPE_COARRAY_DEREGISTER, |
| 77 |
CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY |
| 78 |
} |
| 79 |
caf_deregister_t; |
| 80 |
|
| 81 |
typedef void* caf_token_t; |
| 82 |
typedef void * caf_team_t; |
| 83 |
typedef gfc_array_void gfc_descriptor_t; |
| 84 |
|
| 85 |
/* Linked list of static coarrays registered. */ |
| 86 |
typedef struct caf_static_t { |
| 87 |
caf_token_t token; |
| 88 |
struct caf_static_t *prev; |
| 89 |
} |
| 90 |
caf_static_t; |
| 91 |
|
| 92 |
|
| 93 |
void _gfortran_caf_init (int *, char ***); |
| 94 |
void _gfortran_caf_finalize (void); |
| 95 |
|
| 96 |
int _gfortran_caf_this_image (int); |
| 97 |
int _gfortran_caf_num_images (int, int); |
| 98 |
|
| 99 |
void _gfortran_caf_register (size_t, caf_register_t, caf_token_t *, |
| 100 |
gfc_descriptor_t *, int *, char *, size_t); |
| 101 |
void _gfortran_caf_deregister (caf_token_t *, caf_deregister_t, int *, char *, |
| 102 |
size_t); |
| 103 |
|
| 104 |
void _gfortran_caf_sync_all (int *, char *, size_t); |
| 105 |
void _gfortran_caf_sync_memory (int *, char *, size_t); |
| 106 |
void _gfortran_caf_sync_images (int, int[], int *, char *, size_t); |
| 107 |
|
| 108 |
void _gfortran_caf_stop_numeric (int, bool) |
| 109 |
__attribute__ ((noreturn)); |
| 110 |
void _gfortran_caf_stop_str (const char *, size_t, bool) |
| 111 |
__attribute__ ((noreturn)); |
| 112 |
void _gfortran_caf_error_stop_str (const char *, size_t, bool) |
| 113 |
__attribute__ ((noreturn)); |
| 114 |
void _gfortran_caf_error_stop (int, bool) __attribute__ ((noreturn)); |
| 115 |
void _gfortran_caf_fail_image (void) __attribute__ ((noreturn)); |
| 116 |
|
| 117 |
void _gfortran_caf_co_broadcast (gfc_descriptor_t *, int, int *, char *, size_t); |
| 118 |
void _gfortran_caf_co_sum (gfc_descriptor_t *, int, int *, char *, size_t); |
| 119 |
void _gfortran_caf_co_min (gfc_descriptor_t *, int, int *, char *, int, size_t); |
| 120 |
void _gfortran_caf_co_max (gfc_descriptor_t *, int, int *, char *, int, size_t); |
| 121 |
void _gfortran_caf_co_reduce (gfc_descriptor_t *, void* (*) (void *, void*), |
| 122 |
int, int, int *, char *, int, size_t); |
| 123 |
|
| 124 |
void _gfortran_caf_register_accessor ( |
| 125 |
const int hash, |
| 126 |
void (*accessor) (void *, const int *, void **, int32_t *, void *, |
| 127 |
caf_token_t, const size_t, size_t *, const size_t *)); |
| 128 |
|
| 129 |
void _gfortran_caf_register_accessors_finish (void); |
| 130 |
|
| 131 |
int _gfortran_caf_get_remote_function_index (const int hash); |
| 132 |
|
| 133 |
void _gfortran_caf_get_from_remote ( |
| 134 |
caf_token_t token, const gfc_descriptor_t *opt_src_desc, |
| 135 |
const size_t *opt_src_charlen, const int image_index, const size_t dst_size, |
| 136 |
void **dst_data, size_t *opt_dst_charlen, gfc_descriptor_t *opt_dst_desc, |
| 137 |
const bool may_realloc_dst, const int accessor_index, void *add_data, |
| 138 |
const size_t add_data_size, int *stat, caf_team_t *team, int *team_number); |
| 139 |
|
| 140 |
int32_t _gfortran_caf_is_present_on_remote (caf_token_t token, int, int, |
| 141 |
void *add_data, |
| 142 |
const size_t add_data_size); |
| 143 |
|
| 144 |
void _gfortran_caf_send_to_remote ( |
| 145 |
caf_token_t token, gfc_descriptor_t *opt_dst_desc, |
| 146 |
const size_t *opt_dst_charlen, const int image_index, const size_t src_size, |
| 147 |
const void *src_data, const size_t *opt_src_charlen, |
| 148 |
const gfc_descriptor_t *opt_src_desc, const int accessor_index, |
| 149 |
void *add_data, const size_t add_data_size, int *stat, caf_team_t *team, |
| 150 |
int *team_number); |
| 151 |
|
| 152 |
void _gfortran_caf_transfer_between_remotes ( |
| 153 |
caf_token_t dst_token, gfc_descriptor_t *opt_dst_desc, |
| 154 |
size_t *opt_dst_charlen, const int dst_image_index, |
| 155 |
const int dst_access_index, void *dst_add_data, |
| 156 |
const size_t dst_add_data_size, caf_token_t src_token, |
| 157 |
const gfc_descriptor_t *opt_src_desc, const size_t *opt_src_charlen, |
| 158 |
const int src_image_index, const int src_access_index, void *src_add_data, |
| 159 |
const size_t src_add_data_size, const size_t src_size, |
| 160 |
const bool scalar_transfer, int *dst_stat, int *src_stat, |
| 161 |
caf_team_t *dst_team, int *dst_team_number, caf_team_t *src_team, |
| 162 |
int *src_team_number); |
| 163 |
|
| 164 |
void _gfortran_caf_atomic_define (caf_token_t, size_t, int, void *, int *, |
| 165 |
int, int); |
| 166 |
void _gfortran_caf_atomic_ref (caf_token_t, size_t, int, void *, int *, |
| 167 |
int, int); |
| 168 |
void _gfortran_caf_atomic_cas (caf_token_t, size_t, int, void *, void *, |
| 169 |
void *, int *, int, int); |
| 170 |
void _gfortran_caf_atomic_op (int, caf_token_t, size_t, int, void *, void *, |
| 171 |
int *, int, int); |
| 172 |
|
| 173 |
void _gfortran_caf_lock (caf_token_t, size_t, int, int *, int *, char *, size_t); |
| 174 |
void _gfortran_caf_unlock (caf_token_t, size_t, int, int *, char *, size_t); |
| 175 |
void _gfortran_caf_event_post (caf_token_t, size_t, int, int *, char *, size_t); |
| 176 |
void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, size_t); |
| 177 |
void _gfortran_caf_event_query (caf_token_t, size_t, int, int *, int *); |
| 178 |
|
| 179 |
void _gfortran_caf_failed_images (gfc_descriptor_t *, |
| 180 |
caf_team_t * __attribute__ ((unused)), int *); |
| 181 |
int _gfortran_caf_image_status (int, caf_team_t * __attribute__ ((unused))); |
| 182 |
void _gfortran_caf_stopped_images (gfc_descriptor_t *, |
| 183 |
caf_team_t * __attribute__ ((unused)), |
| 184 |
int *); |
| 185 |
|
| 186 |
void _gfortran_caf_random_init (bool, bool); |
| 187 |
|
| 188 |
#endif /* LIBCAF_H */ |