mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
e9f389f0da
commit
0a1138af63
|
@ -1,3 +1,18 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2011-06-11 Janne Blomqvist <jb@gcc.gnu.org>
|
2011-06-11 Janne Blomqvist <jb@gcc.gnu.org>
|
||||||
|
|
||||||
* io/unix.c (buf_seek): Return error if file is not seekable.
|
* io/unix.c (buf_seek): Return error if file is not seekable.
|
||||||
|
|
|
@ -38,14 +38,22 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
||||||
#define STAT_LOCKED_OTHER_IMAGE 2
|
#define STAT_LOCKED_OTHER_IMAGE 2
|
||||||
#define STAT_STOPPED_IMAGE 3
|
#define STAT_STOPPED_IMAGE 3
|
||||||
|
|
||||||
|
/* Describes what type of array we are registerring. */
|
||||||
typedef enum caf_register_t {
|
typedef enum caf_register_t {
|
||||||
CAF_REGTYPE_COARRAY,
|
CAF_REGTYPE_COARRAY_STATIC,
|
||||||
|
CAF_REGTYPE_COARRAY_ALLOC,
|
||||||
CAF_REGTYPE_LOCK,
|
CAF_REGTYPE_LOCK,
|
||||||
CAF_REGTYPE_LOCK_COMP
|
CAF_REGTYPE_LOCK_COMP
|
||||||
}
|
}
|
||||||
caf_register_t;
|
caf_register_t;
|
||||||
|
|
||||||
|
/* Linked list of static coarrays registered. */
|
||||||
|
typedef struct caf_static_t {
|
||||||
|
void **token;
|
||||||
|
struct caf_static_t *prev;
|
||||||
|
}
|
||||||
|
caf_static_t;
|
||||||
|
|
||||||
|
|
||||||
void _gfortran_caf_init (int *, char ***, int *, int *);
|
void _gfortran_caf_init (int *, char ***, int *, int *);
|
||||||
void _gfortran_caf_finalize (void);
|
void _gfortran_caf_finalize (void);
|
||||||
|
|
|
@ -42,6 +42,8 @@ static int caf_mpi_initialized;
|
||||||
static int caf_this_image;
|
static int caf_this_image;
|
||||||
static int caf_num_images;
|
static int caf_num_images;
|
||||||
|
|
||||||
|
caf_static_t *caf_static_list = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Initialize coarray program. This routine assumes that no other
|
/* Initialize coarray program. This routine assumes that no other
|
||||||
MPI initialization happened before; otherwise MPI_Initialized
|
MPI initialization happened before; otherwise MPI_Initialized
|
||||||
|
@ -52,16 +54,23 @@ static int caf_num_images;
|
||||||
void
|
void
|
||||||
_gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
|
_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
|
if (caf_num_images == 0)
|
||||||
Fortran. */
|
{
|
||||||
MPI_Initialized (&caf_mpi_initialized);
|
/* caf_mpi_initialized is only true if the main program is
|
||||||
if (!caf_mpi_initialized)
|
not written in Fortran. */
|
||||||
MPI_Init (argc, argv);
|
MPI_Initialized (&caf_mpi_initialized);
|
||||||
|
if (!caf_mpi_initialized)
|
||||||
|
MPI_Init (argc, argv);
|
||||||
|
|
||||||
MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image);
|
MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images);
|
||||||
*this_image = ++caf_this_image;
|
MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image);
|
||||||
MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images);
|
caf_this_image++;
|
||||||
*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
|
void
|
||||||
_gfortran_caf_finalize (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)
|
if (!caf_mpi_initialized)
|
||||||
MPI_Finalize ();
|
MPI_Finalize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
_gfortran_caf_register (ptrdiff_t size,
|
_gfortran_caf_register (ptrdiff_t size, caf_register_t type,
|
||||||
caf_register_t type __attribute__ ((unused)),
|
|
||||||
void **token)
|
void **token)
|
||||||
{
|
{
|
||||||
*token = NULL;
|
void *local;
|
||||||
return malloc (size);
|
|
||||||
|
/* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
||||||
Note: For performance reasons -fcoarry=single should be used
|
Note: For performance reasons -fcoarry=single should be used
|
||||||
rather than this library. */
|
rather than this library. */
|
||||||
|
|
||||||
|
/* Global variables. */
|
||||||
|
caf_static_t *caf_static_list = NULL;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_gfortran_caf_init (int *argc __attribute__ ((unused)),
|
_gfortran_caf_init (int *argc __attribute__ ((unused)),
|
||||||
|
@ -49,16 +52,32 @@ _gfortran_caf_init (int *argc __attribute__ ((unused)),
|
||||||
void
|
void
|
||||||
_gfortran_caf_finalize (void)
|
_gfortran_caf_finalize (void)
|
||||||
{
|
{
|
||||||
|
while (caf_static_list != NULL)
|
||||||
|
{
|
||||||
|
free(caf_static_list->token[0]);
|
||||||
|
caf_static_list = caf_static_list->prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
_gfortran_caf_register (ptrdiff_t size,
|
_gfortran_caf_register (ptrdiff_t size, caf_register_t type,
|
||||||
caf_register_t type __attribute__ ((unused)),
|
|
||||||
void **token)
|
void **token)
|
||||||
{
|
{
|
||||||
*token = NULL;
|
void *local;
|
||||||
return malloc (size);
|
|
||||||
|
local = malloc (size);
|
||||||
|
token = malloc (sizeof (void*) * 1);
|
||||||
|
token[0] = local;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,6 +97,7 @@ _gfortran_caf_sync_all (int *stat,
|
||||||
*stat = 0;
|
*stat = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_gfortran_caf_sync_images (int count __attribute__ ((unused)),
|
_gfortran_caf_sync_images (int count __attribute__ ((unused)),
|
||||||
int images[] __attribute__ ((unused)),
|
int images[] __attribute__ ((unused)),
|
||||||
|
|
Loading…
Reference in New Issue