summaryrefslogtreecommitdiff
path: root/libgfortran/caf
diff options
context:
space:
mode:
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2011-04-06 18:29:55 +0000
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2011-04-06 18:29:55 +0000
commit99c0d3346eac3c81d6853fde8f576f138f2ecff0 (patch)
tree3deb402a06fad3e4889609797057e8740cd47649 /libgfortran/caf
parent887423c0bcb18daa8fbb7d4cac5e3f79c8292b45 (diff)
downloadgcc-99c0d3346eac3c81d6853fde8f576f138f2ecff0.tar.gz
2011-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/18918 * caf/mpi.c (_gfortran_caf_init, _gfortran_caf_finalize): Add global variable caf_mpi_initialized and use it for when finalizing. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@172059 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/caf')
-rw-r--r--libgfortran/caf/mpi.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libgfortran/caf/mpi.c b/libgfortran/caf/mpi.c
index 634e240bf19..9e4db916c85 100644
--- a/libgfortran/caf/mpi.c
+++ b/libgfortran/caf/mpi.c
@@ -36,6 +36,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
static void error_stop (int error) __attribute__ ((noreturn));
/* Global variables. */
+static int caf_mpi_initialized;
static int caf_this_image;
static int caf_num_images;
static MPI_Win caf_world_window;
@@ -50,12 +51,10 @@ static MPI_Win caf_world_window;
void
_gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
{
- int flag;
-
- /* The following is only the case if one does not have a Fortran
- main program. */
- MPI_Initialized (&flag);
- if (!flag)
+ /* 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_rank (MPI_COMM_WORLD, &caf_this_image);
@@ -69,15 +68,15 @@ _gfortran_caf_init (int *argc, char ***argv, int *this_image, int *num_images)
}
-/* Finalize coarray program. Note: This is only called before the
- program ends; thus the MPI_Initialized status of _gfortran_caf_init
- does not play a role. */
+/* Finalize coarray program. */
void
_gfortran_caf_finalize (void)
{
MPI_Win_free (&caf_world_window);
- MPI_Finalize ();
+
+ if (!caf_mpi_initialized)
+ MPI_Finalize ();
}