diff mbox

[Fortra] Add STAT_STOPPED_IMAGE to SYC ALL/SYNC IMAGES

Message ID 4E1607CB.9050400@gmail.com
State New
Headers show

Commit Message

Daniel Carrera July 7, 2011, 7:23 p.m. UTC
Hello,

I'd like to submit the attached patch. This patch was just discussed in 
the gfortran list. It fixes a couple of TODO items in the MPI library. 
It is a simple patch.

libgfortran/ChangeLog

2011-07-07  Daniel Carrera <dcarrera@gmail.com>

	* mpi.c (_gfortran_caf_sync_all): Add STAT_STOPPED_IMAGE as a
	possible status value.
	(_gfortran_caf_sync_images): Ditto.


Cheers,
Daniel.

Comments

Tobias Burnus July 9, 2011, 11:17 a.m. UTC | #1
Daniel Carrera wrote:
> I'd like to submit the attached patch. This patch was just discussed 
> in the gfortran list. It fixes a couple of TODO items in the MPI 
> library. It is a simple patch.

OK with the following nits fixed.

* As you have now an SVN account, can you add yourself to the 
./MAINTAINERS file (section: "Write After Approval")? Don't forget to 
write an email to gcc-patches@ with that patch after committal.

> libgfortran/ChangeLog
>
> 2011-07-07  Daniel Carrera <dcarrera@gmail.com>
>
>     * mpi.c (_gfortran_caf_sync_all): Add STAT_STOPPED_IMAGE as a
>     possible status value.
>     (_gfortran_caf_sync_images): Ditto.

Change "mpi.c" to "caf/mpi.c" - the file name is relative to the 
ChangeLog file.

> +      char msg[30];
> +      int len;
> +
> +      if (caf_is_finalized)
> +	len = snprintf (msg, 30, "ERROR: Image %d is stopped", caf_this_image);
> +      else
> +	len = snprintf (msg, 30, "SYNC ALL failed");

I would like to avoid magic numbers like "30"; in this case, one can 
replace the 30 in snprintf by a simple "sizeof (msg)".


> +      if (caf_is_finalized)
> +	len = snprintf (msg, 30, "ERROR: Image %d is stopped", caf_this_image);
> +      else
> +	len = snprintf (msg, 30, "SYNC IMAGES failed");

Ditto.

Tobias
diff mbox

Patch

Index: libgfortran/caf/mpi.c
===================================================================
--- libgfortran/caf/mpi.c	(revision 175973)
+++ libgfortran/caf/mpi.c	(working copy)
@@ -179,35 +179,44 @@  _gfortran_caf_deregister (void **token _
 void
 _gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len)
 {
-  /* TODO: Is ierr correct? When should STAT_STOPPED_IMAGE be used?  */
-  int ierr = MPI_Barrier (MPI_COMM_WORLD);
+  int ierr;
+
+  if (unlikely(caf_is_finalized))
+    ierr = STAT_STOPPED_IMAGE;
+  else
+    ierr = MPI_Barrier (MPI_COMM_WORLD);
 
   if (stat)
     *stat = ierr;
 
-  if (ierr)
+  if (ierr) 
     {
-      const char msg[] = "SYNC ALL failed";
+      char msg[30];
+      int len;
+
+      if (caf_is_finalized)
+	len = snprintf (msg, 30, "ERROR: Image %d is stopped", caf_this_image);
+      else
+	len = snprintf (msg, 30, "SYNC ALL failed");
+
       if (errmsg_len > 0)
 	{
-	  int len = ((int) sizeof (msg) > errmsg_len) ? errmsg_len
-						      : (int) sizeof (msg);
+	  len = (len > errmsg_len) ? errmsg_len : len;
 	  memcpy (errmsg, msg, len);
 	  if (errmsg_len > len)
 	    memset (&errmsg[len], ' ', errmsg_len-len);
 	}
       else
 	{
-	  fprintf (stderr, "SYNC ALL failed\n");
+	  fprintf (stderr, "%s\n", msg);
 	  error_stop (ierr);
 	}
     }
 }
 
-
 /* SYNC IMAGES. Note: SYNC IMAGES(*) is passed as count == -1 while
    SYNC IMAGES([]) has count == 0. Note further that SYNC IMAGES(*)
-   is not equivalent to SYNC ALL. */
+   is not equivalent to SYNC ALL.  */
 void
 _gfortran_caf_sync_images (int count, int images[], int *stat, char *errmsg,
 			   int errmsg_len)
@@ -243,25 +252,34 @@  _gfortran_caf_sync_images (int count, in
     }
 
   /* Handle SYNC IMAGES(*).  */
-  /* TODO: Is ierr correct? When should STAT_STOPPED_IMAGE be used?  */
-  ierr = MPI_Barrier (MPI_COMM_WORLD);
+  if (unlikely(caf_is_finalized))
+    ierr = STAT_STOPPED_IMAGE;
+  else
+    ierr = MPI_Barrier (MPI_COMM_WORLD);
+
   if (stat)
     *stat = ierr;
 
-  if (ierr)
+  if (ierr) 
     {
-      const char msg[] = "SYNC IMAGES failed";
+      char msg[30];
+      int len;
+
+      if (caf_is_finalized)
+	len = snprintf (msg, 30, "ERROR: Image %d is stopped", caf_this_image);
+      else
+	len = snprintf (msg, 30, "SYNC IMAGES failed");
+      
       if (errmsg_len > 0)
 	{
-	  int len = ((int) sizeof (msg) > errmsg_len) ? errmsg_len
-						      : (int) sizeof (msg);
+	  len = (len > errmsg_len) ? errmsg_len : len;
 	  memcpy (errmsg, msg, len);
 	  if (errmsg_len > len)
 	    memset (&errmsg[len], ' ', errmsg_len-len);
 	}
       else
 	{
-	  fprintf (stderr, "SYNC IMAGES failed\n");
+	  fprintf (stderr, "%s\n", msg);
 	  error_stop (ierr);
 	}
     }