public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortra] Add STAT_STOPPED_IMAGE to SYC ALL/SYNC IMAGES
@ 2011-07-07 19:29 Daniel Carrera
  2011-07-09 12:03 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Carrera @ 2011-07-07 19:29 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

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.
-- 
I'm not overweight, I'm undertall.

[-- Attachment #2: stat-stopped-image.diff --]
[-- Type: text/x-patch, Size: 2714 bytes --]

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);
 	}
     }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, Fortra] Add STAT_STOPPED_IMAGE to SYC ALL/SYNC IMAGES
  2011-07-07 19:29 [Patch, Fortra] Add STAT_STOPPED_IMAGE to SYC ALL/SYNC IMAGES Daniel Carrera
@ 2011-07-09 12:03 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2011-07-09 12:03 UTC (permalink / raw)
  To: Daniel Carrera; +Cc: gfortran, gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-09 11:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-07 19:29 [Patch, Fortra] Add STAT_STOPPED_IMAGE to SYC ALL/SYNC IMAGES Daniel Carrera
2011-07-09 12:03 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).