diff options
Diffstat (limited to 'libgfortran/caf')
-rw-r--r-- | libgfortran/caf/libcaf.h | 17 | ||||
-rw-r--r-- | libgfortran/caf/mpi.c | 40 | ||||
-rw-r--r-- | libgfortran/caf/single.c | 36 |
3 files changed, 62 insertions, 31 deletions
diff --git a/libgfortran/caf/libcaf.h b/libgfortran/caf/libcaf.h index 7ecd76fcecb..8b8fd3e2b8f 100644 --- a/libgfortran/caf/libcaf.h +++ b/libgfortran/caf/libcaf.h @@ -26,8 +26,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #ifndef LIBCAF_H #define LIBCAF_H +#include <stdbool.h> +#include <stddef.h> /* For size_t. */ #include <stdint.h> /* For int32_t. */ -#include <stddef.h> /* For ptrdiff_t. */ #ifndef __GNUC__ #define __attribute__(x) @@ -55,21 +56,25 @@ typedef enum caf_register_t { } caf_register_t; +typedef void* caf_token_t; + /* Linked list of static coarrays registered. */ typedef struct caf_static_t { - void **token; + caf_token_t token; struct caf_static_t *prev; } caf_static_t; -void _gfortran_caf_init (int *, char ***, int *, int *); +void _gfortran_caf_init (int *, char ***); void _gfortran_caf_finalize (void); -void * _gfortran_caf_register (ptrdiff_t, caf_register_t, void ***, int *, - char *, int); -void _gfortran_caf_deregister (void ***, int *, char *, int); +int _gfortran_caf_this_image (int); +int _gfortran_caf_num_images (int, bool); +void *_gfortran_caf_register (size_t, caf_register_t, caf_token_t *, int *, + char *, int); +void _gfortran_caf_deregister (caf_token_t *, int *, char *, int); void _gfortran_caf_sync_all (int *, char *, int); void _gfortran_caf_sync_images (int, int[], int *, char *, int); diff --git a/libgfortran/caf/mpi.c b/libgfortran/caf/mpi.c index da7185ed09f..fe2baf4633c 100644 --- a/libgfortran/caf/mpi.c +++ b/libgfortran/caf/mpi.c @@ -34,6 +34,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* Define GFC_CAF_CHECK to enable run-time checking. */ /* #define GFC_CAF_CHECK 1 */ +typedef void ** mpi_token_t; +#define TOKEN(X) ((mpi_token_t) (X)) static void error_stop (int error) __attribute__ ((noreturn)); @@ -73,7 +75,7 @@ caf_runtime_error (const char *message, ...) libaray is initialized. */ void -_gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images) +_gfortran_caf_init (int *argc, char ***argv) { if (caf_num_images == 0) { @@ -87,11 +89,6 @@ _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images) MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image); caf_this_image++; } - - if (this_image) - *this_image = caf_this_image; - if (num_images) - *num_images = caf_num_images; } @@ -104,8 +101,8 @@ _gfortran_caf_finalize (void) { caf_static_t *tmp = caf_static_list->prev; - free (caf_static_list->token[caf_this_image-1]); - free (caf_static_list->token); + free (TOKEN (caf_static_list->token)[caf_this_image-1]); + free (TOKEN (caf_static_list->token)); free (caf_static_list); caf_static_list = tmp; } @@ -117,8 +114,23 @@ _gfortran_caf_finalize (void) } +int +_gfortran_caf_this_image (int distance __attribute__ ((unused))) +{ + return caf_this_image; +} + + +int +_gfortran_caf_num_images (int distance __attribute__ ((unused)), + bool failed __attribute__ ((unused))) +{ + return caf_num_images; +} + + void * -_gfortran_caf_register (ptrdiff_t size, caf_register_t type, void ***token, +_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, int *stat, char *errmsg, int errmsg_len) { void *local; @@ -129,17 +141,17 @@ _gfortran_caf_register (ptrdiff_t size, caf_register_t type, void ***token, /* Start MPI if not already started. */ if (caf_num_images == 0) - _gfortran_caf_init (NULL, NULL, NULL, NULL); + _gfortran_caf_init (NULL, NULL); /* Token contains only a list of pointers. */ local = malloc (size); - *token = malloc (sizeof (void*) * caf_num_images); + *token = malloc (sizeof (mpi_token_t) * caf_num_images); if (unlikely (local == NULL || *token == NULL)) goto error; /* token[img-1] is the address of the token in image "img". */ - err = MPI_Allgather (&local, sizeof (void*), MPI_BYTE, *token, + err = MPI_Allgather (&local, sizeof (void*), MPI_BYTE, TOKEN (*token), sizeof (void*), MPI_BYTE, MPI_COMM_WORLD); if (unlikely (err)) @@ -192,7 +204,7 @@ error: void -_gfortran_caf_deregister (void ***token, int *stat, char *errmsg, int errmsg_len) +_gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errmsg_len) { if (unlikely (caf_is_finalized)) { @@ -220,7 +232,7 @@ _gfortran_caf_deregister (void ***token, int *stat, char *errmsg, int errmsg_len if (stat) *stat = 0; - free ((*token)[caf_this_image-1]); + free (TOKEN (*token)[caf_this_image-1]); free (*token); } diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c index 551b9aa784d..cf1ced85d90 100644 --- a/libgfortran/caf/single.c +++ b/libgfortran/caf/single.c @@ -32,6 +32,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* Define GFC_CAF_CHECK to enable run-time checking. */ /* #define GFC_CAF_CHECK 1 */ +typedef void* single_token_t; +#define TOKEN(X) ((single_token_t) (X)) + /* Single-image implementation of the CAF library. Note: For performance reasons -fcoarry=single should be used rather than this library. */ @@ -57,11 +60,8 @@ caf_runtime_error (const char *message, ...) void _gfortran_caf_init (int *argc __attribute__ ((unused)), - char ***argv __attribute__ ((unused)), - int *this_image, int *num_images) + char ***argv __attribute__ ((unused))) { - *this_image = 1; - *num_images = 1; } @@ -71,7 +71,6 @@ _gfortran_caf_finalize (void) while (caf_static_list != NULL) { caf_static_t *tmp = caf_static_list->prev; - free (caf_static_list->token[0]); free (caf_static_list->token); free (caf_static_list); caf_static_list = tmp; @@ -79,15 +78,29 @@ _gfortran_caf_finalize (void) } +int +_gfortran_caf_this_image (int distance __attribute__ ((unused))) +{ + return 1; +} + + +int +_gfortran_caf_num_images (int distance __attribute__ ((unused)), + bool failed __attribute__ ((unused))) +{ + return 1; +} + + void * -_gfortran_caf_register (ptrdiff_t size, caf_register_t type, void ***token, +_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, int *stat, char *errmsg, int errmsg_len) { void *local; local = malloc (size); - *token = malloc (sizeof (void*) * 1); - (*token)[0] = local; + *token = malloc (sizeof (single_token_t)); if (unlikely (local == NULL || token == NULL)) { @@ -109,6 +122,8 @@ _gfortran_caf_register (ptrdiff_t size, caf_register_t type, void ***token, caf_runtime_error (msg); } + *token = local; + if (stat) *stat = 0; @@ -124,12 +139,11 @@ _gfortran_caf_register (ptrdiff_t size, caf_register_t type, void ***token, void -_gfortran_caf_deregister (void ***token, int *stat, +_gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg __attribute__ ((unused)), int errmsg_len __attribute__ ((unused))) { - free ((*token)[0]); - free (*token); + free (TOKEN(*token)); if (stat) *stat = 0; |