From: Tobias Burnus Date: Wed, 6 Apr 2011 18:29:55 +0000 (+0200) Subject: re PR fortran/18918 (Eventually support Fortran 2008's coarrays [co-arrays]) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6eb87b330f273fa62e701c0c52096d294b9227b1;p=gcc.git re PR fortran/18918 (Eventually support Fortran 2008's coarrays [co-arrays]) 2011-04-06 Tobias Burnus PR fortran/18918 * caf/mpi.c (_gfortran_caf_init, _gfortran_caf_finalize): Add global variable caf_mpi_initialized and use it for when finalizing. From-SVN: r172059 --- diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index bae9d3c5d45..e8f714a2f75 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,10 @@ +2011-04-06 Tobias Burnus + + PR fortran/18918 + * caf/mpi.c (_gfortran_caf_init, _gfortran_caf_finalize): + Add global variable caf_mpi_initialized and use it for when + finalizing. + 2011-04-04 Tobias Burnus * unix.c: Adapt stat DEFINEs since MinGW64 supports LFS. 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 (); }