re PR fortran/18918 (Eventually support Fortran 2008's coarrays [co-arrays])

2011-05-06  Tobias Burnus  <burnus@net-b.de>

        PR fortran/18918
        * caf/libcaf.h: Cleanup headers.
        (_gfortran_caf_critical, _gfortran_caf_end_critical): Make stub.
        (caf_register_t): New enum.
        (_gfortran_caf_register, _gfortran_caf_deregister): New prototype.
        * caf/single.c (_gfortran_caf_critical,
        _gfortran_caf_end_critical): Remove.
        (_gfortran_caf_register, _gfortran_caf_deregister): New functions.
        * caf/mpi.c (_gfortran_caf_critical,
        _gfortran_caf_end_critical): Remove.
        (_gfortran_caf_register, _gfortran_caf_deregister): New functions.
        (caf_world_window): Remove global variable.
        (_gfortran_caf_init): Fix off-by-one error of this_image.

From-SVN: r173505
This commit is contained in:
Tobias Burnus 2011-05-06 20:35:00 +02:00 committed by Tobias Burnus
parent 7b040949f6
commit cc9ae24cbe
4 changed files with 81 additions and 41 deletions

View File

@ -1,3 +1,19 @@
2011-05-06 Tobias Burnus <burnus@net-b.de>
PR fortran/18918
* caf/libcaf.h: Cleanup headers.
(_gfortran_caf_critical, _gfortran_caf_end_critical): Make stub.
(caf_register_t): New enum.
(_gfortran_caf_register, _gfortran_caf_deregister): New prototype.
* caf/single.c (_gfortran_caf_critical,
_gfortran_caf_end_critical): Remove.
(_gfortran_caf_register, _gfortran_caf_deregister): New functions.
* caf/mpi.c (_gfortran_caf_critical,
_gfortran_caf_end_critical): Remove.
(_gfortran_caf_register, _gfortran_caf_deregister): New functions.
(caf_world_window): Remove global variable.
(_gfortran_caf_init): Fix off-by-one error of this_image.
2011-05-04 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2011-05-04 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/48787 PR libgfortran/48787

View File

@ -27,8 +27,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#ifndef LIBCAF_H #ifndef LIBCAF_H
#define LIBCAF_H #define LIBCAF_H
#include <stdint.h> #include <stdint.h> /* For int32_t. */
#include <string.h> #include <stddef.h> /* For ptrdiff_t. */
/* Definitions of the Fortran 2008 standard; need to kept in sync with /* Definitions of the Fortran 2008 standard; need to kept in sync with
ISO_FORTRAN_ENV, cf. libgfortran.h. */ ISO_FORTRAN_ENV, cf. libgfortran.h. */
@ -38,16 +39,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define STAT_STOPPED_IMAGE 3 #define STAT_STOPPED_IMAGE 3
typedef enum caf_register_t {
CAF_REGTYPE_COARRAY,
CAF_REGTYPE_LOCK,
CAF_REGTYPE_LOCK_COMP
}
caf_register_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);
void * _gfortran_caf_register (ptrdiff_t, caf_register_t, void **);
int _gfortran_caf_deregister (void **);
int _gfortran_caf_sync_all (char *, int); int _gfortran_caf_sync_all (char *, int);
int _gfortran_caf_sync_images (int count, int images[], char *, int); int _gfortran_caf_sync_images (int, int[], char *, int);
void _gfortran_caf_critical (void); /* FIXME: The CRITICAL functions should be removed;
void _gfortran_caf_end_critical (void); the functionality is better represented using Coarray's lock feature. */
void _gfortran_caf_critical (void) { }
void _gfortran_caf_end_critical (void) { }
void _gfortran_caf_error_stop_str (const char *, int32_t) __attribute__ ((noreturn));
void _gfortran_caf_error_stop_str (const char *, int32_t)
__attribute__ ((noreturn));
void _gfortran_caf_error_stop (int32_t) __attribute__ ((noreturn)); void _gfortran_caf_error_stop (int32_t) __attribute__ ((noreturn));
#endif /* LIBCAF_H */ #endif /* LIBCAF_H */

View File

@ -27,8 +27,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "libcaf.h" #include "libcaf.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> /* For memcpy. */
#include <mpi.h> #include <mpi.h>
/* Define GFC_CAF_CHECK to enable run-time checking. */ /* Define GFC_CAF_CHECK to enable run-time checking. */
/* #define GFC_CAF_CHECK 1 */ /* #define GFC_CAF_CHECK 1 */
@ -39,7 +41,6 @@ static void error_stop (int error) __attribute__ ((noreturn));
static int caf_mpi_initialized; 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;
static MPI_Win caf_world_window;
/* Initialize coarray program. This routine assumes that no other /* Initialize coarray program. This routine assumes that no other
@ -58,13 +59,9 @@ _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
MPI_Init (argc, argv); MPI_Init (argc, argv);
MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image); MPI_Comm_rank (MPI_COMM_WORLD, &caf_this_image);
*this_image = caf_this_image + 1; *this_image = ++caf_this_image;
MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images); MPI_Comm_size (MPI_COMM_WORLD, &caf_num_images);
*num_images = caf_num_images; *num_images = caf_num_images;
/* Obtain window for CRITICAL section locking. */
MPI_Win_create (NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
&caf_world_window);
} }
@ -73,13 +70,28 @@ _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
void void
_gfortran_caf_finalize (void) _gfortran_caf_finalize (void)
{ {
MPI_Win_free (&caf_world_window);
if (!caf_mpi_initialized) if (!caf_mpi_initialized)
MPI_Finalize (); MPI_Finalize ();
} }
void *
_gfortran_caf_register (ptrdiff_t size,
caf_register_t type __attribute__ ((unused)),
void **token)
{
*token = NULL;
return malloc (size);
}
int
_gfortran_caf_deregister (void **token __attribute__ ((unused)))
{
return 0;
}
/* SYNC ALL - the return value matches Fortran's STAT argument. */ /* SYNC ALL - the return value matches Fortran's STAT argument. */
int int
@ -156,22 +168,6 @@ _gfortran_caf_sync_images (int count, int images[], char *errmsg,
} }
/* CRITICAL BLOCK. */
void
_gfortran_caf_critical (void)
{
MPI_Win_lock (MPI_LOCK_SHARED, 0, 0, caf_world_window);
}
void
_gfortran_caf_end_critical (void)
{
MPI_Win_unlock (0, caf_world_window);
}
/* ERROR STOP the other images. */ /* ERROR STOP the other images. */
static void static void

View File

@ -26,16 +26,16 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "libcaf.h" #include "libcaf.h"
#include <stdio.h> /* For fputs and fprintf. */ #include <stdio.h> /* For fputs and fprintf. */
#include <stdlib.h> /* For exit. */ #include <stdlib.h> /* For exit and malloc. */
/* Define GFC_CAF_CHECK to enable run-time checking. */ /* Define GFC_CAF_CHECK to enable run-time checking. */
/* #define GFC_CAF_CHECK 1 */ /* #define GFC_CAF_CHECK 1 */
/* Single-image implementation of the CAF library. /* Single-image implementation of the CAF library.
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. */
void void
_gfortran_caf_init (int *argc __attribute__ ((unused)), _gfortran_caf_init (int *argc __attribute__ ((unused)),
char ***argv __attribute__ ((unused)), char ***argv __attribute__ ((unused)),
@ -45,11 +45,30 @@ _gfortran_caf_init (int *argc __attribute__ ((unused)),
*num_images = 1; *num_images = 1;
} }
void void
_gfortran_caf_finalize (void) _gfortran_caf_finalize (void)
{ {
} }
void *
_gfortran_caf_register (ptrdiff_t size,
caf_register_t type __attribute__ ((unused)),
void **token)
{
*token = NULL;
return malloc (size);
}
int
_gfortran_caf_deregister (void **token __attribute__ ((unused)))
{
return 0;
}
int int
_gfortran_caf_sync_all (char *errmsg __attribute__ ((unused)), _gfortran_caf_sync_all (char *errmsg __attribute__ ((unused)),
int errmsg_len __attribute__ ((unused))) int errmsg_len __attribute__ ((unused)))
@ -78,15 +97,6 @@ _gfortran_caf_sync_images (int count __attribute__ ((unused)),
return 0; return 0;
} }
void
_gfortran_caf_critical (void)
{
}
void
_gfortran_caf_end_critical (void)
{
}
void void
_gfortran_caf_error_stop_str (const char *string, int32_t len) _gfortran_caf_error_stop_str (const char *string, int32_t len)
@ -99,6 +109,7 @@ _gfortran_caf_error_stop_str (const char *string, int32_t len)
exit (1); exit (1);
} }
void void
_gfortran_caf_error_stop (int32_t error) _gfortran_caf_error_stop (int32_t error)
{ {