diff options
author | Daniel Carrera <dcarrera@gmail.com> | 2011-06-16 23:09:36 +0000 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2011-06-17 01:09:36 +0200 |
commit | 0a1138af63725af5098e259237492b819631e05b (patch) | |
tree | 1a0780f50a63ba3471f12fc0843bb7bd1dcd422b /libgfortran/caf/mpi.c | |
parent | e9f389f0da308bdb9259afc8be4b7b207acd3900 (diff) | |
download | gcc-0a1138af63725af5098e259237492b819631e05b.zip gcc-0a1138af63725af5098e259237492b819631e05b.tar.gz gcc-0a1138af63725af5098e259237492b819631e05b.tar.bz2 |
single.c (_gfortran_caf_register): Store the address of all static coarrays in a linked list.
2011-06-17 Daniel Carrera <dcarrera@gmail.com>
* caf/single.c (_gfortran_caf_register): Store the address
of all static coarrays in a linked list.
(_gfortran_caf_finalize): Free memory of staic coarrays.
* caf/mpi.c (_gfortran_caf_register): Store the address
of all static coarrays in a linked list. Initialize MPI
if necessary.
(_gfortran_caf_finalize): Free memory of staic coarrays.
(_gfortran_caf_init): Check if MPI is already initialized
before initializing again.
* caf/libcaf.h: Add a type to caf_register_t to distinguish
static coarrays and add the type caf_static_t to make the
linked list of static coarrays.
From-SVN: r175124
Diffstat (limited to 'libgfortran/caf/mpi.c')
-rw-r--r-- | libgfortran/caf/mpi.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/libgfortran/caf/mpi.c b/libgfortran/caf/mpi.c index e64670e..83f39f6 100644 --- a/libgfortran/caf/mpi.c +++ b/libgfortran/caf/mpi.c @@ -42,6 +42,8 @@ static int caf_mpi_initialized; static int caf_this_image; static int caf_num_images; +caf_static_t *caf_static_list = NULL; + /* Initialize coarray program. This routine assumes that no other MPI initialization happened before; otherwise MPI_Initialized @@ -52,16 +54,23 @@ static int caf_num_images; void _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images) { - /* caf_mpi_initialized is only true if the main program is not written in - Fortran. */ - MPI_Initialized (&caf_mpi_initialized); - if (!caf_mpi_initialized) - MPI_Init (argc, argv); + if (caf_num_images == 0) + { + /* caf_mpi_initialized is only true if the main program is + not written in Fortran. */ + MPI_Initialized (&caf_mpi_initialized); + if (!caf_mpi_initialized) + MPI_Init (argc, argv); + + MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images); + MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image); + caf_this_image++; + } - MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image); - *this_image = ++caf_this_image; - MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images); - *num_images = caf_num_images; + if (this_image) + *this_image = caf_this_image; + if (num_images) + *num_images = caf_num_images; } @@ -70,18 +79,43 @@ _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images) void _gfortran_caf_finalize (void) { + while (caf_static_list != NULL) + { + free(caf_static_list->token[caf_this_image-1]); + caf_static_list = caf_static_list->prev; + } + if (!caf_mpi_initialized) MPI_Finalize (); } void * -_gfortran_caf_register (ptrdiff_t size, - caf_register_t type __attribute__ ((unused)), +_gfortran_caf_register (ptrdiff_t size, caf_register_t type, void **token) { - *token = NULL; - return malloc (size); + void *local; + + /* Start MPI if not already started. */ + if (caf_num_images == 0) + _gfortran_caf_init (NULL, NULL, NULL, NULL); + + /* Token contains only a list of pointers. */ + local = malloc (size); + token = malloc (sizeof (void*) * caf_num_images); + + /* token[img-1] is the address of the token in image "img". */ + MPI_Allgather (&local, sizeof (void*), MPI_BYTE, + token, sizeof (void*), MPI_BYTE, MPI_COMM_WORLD); + + if (type == CAF_REGTYPE_COARRAY_STATIC) + { + caf_static_t *tmp = malloc (sizeof (caf_static_t)); + tmp->prev = caf_static_list; + tmp->token = token; + caf_static_list = tmp; + } + return local; } |