]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Make SYNC IMAGES(*) work by handling size of -1 in library.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 1 Jan 2021 11:12:49 +0000 (12:12 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 1 Jan 2021 11:12:49 +0000 (12:12 +0100)
libgfortran/ChangeLog:

* caf_shared/sync.c (sync_table): Change size argument and index
to int.
* caf_shared/sync.h (sync_table): Adjust prototype.
* caf_shared/wrapper.c (cas_sync_images): Add s argument to int,
adjust call to sync_table.

gcc/testsuite/ChangeLog:

* gfortran.dg/caf-shared/sync_images_1.f90: New test.
* gfortran.dg/caf-shared/sync_images_2.f90: New test.

gcc/testsuite/gfortran.dg/caf-shared/sync_images_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/caf-shared/sync_images_2.f90 [new file with mode: 0644]
libgfortran/caf_shared/sync.c
libgfortran/caf_shared/sync.h
libgfortran/caf_shared/wrapper.c

diff --git a/gcc/testsuite/gfortran.dg/caf-shared/sync_images_1.f90 b/gcc/testsuite/gfortran.dg/caf-shared/sync_images_1.f90
new file mode 100644 (file)
index 0000000..c06b763
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+! { dg-output "1234" }
+program main
+  implicit none
+  integer :: n, me
+  n = num_images()
+  me = this_image()
+  if (me /= 1) sync images (me - 1)
+  write (*,'(I0)',advance="no") me
+  if (me /= n)  sync images (me+1)
+  sync all
+end program main
diff --git a/gcc/testsuite/gfortran.dg/caf-shared/sync_images_2.f90 b/gcc/testsuite/gfortran.dg/caf-shared/sync_images_2.f90
new file mode 100644 (file)
index 0000000..f1d6334
--- /dev/null
@@ -0,0 +1,5 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+program main
+  sync images(*)
+end program main
index 76612dc477df91d83895d9737a04f192434f9c5d..71f7a34497ac5b7d75812ee62c1f41cf3032b015 100644 (file)
@@ -84,7 +84,7 @@ sync_iface_init (sync_iface *si, alloc_iface *ai, shared_memory *sm)
 
 /* TODO: Maybe check whether synchronizing image is still alive.  */
 void
-sync_table (sync_iface *si, int *images, size_t size)
+sync_table (sync_iface *si, int *images, int size)
 {
 #if defined(DEBUG_NATIVE_COARRAY) && DEBUG_NATIVE_COARRAY
   dprintf (2,
@@ -94,25 +94,48 @@ sync_table (sync_iface *si, int *images, size_t size)
     dprintf (2, "%d ", images[d_i]);
   dprintf (2, "\n");
 #endif
-  size_t i;
+  int i;
   int done;
   int *table = get_locked_table (si);
-  for (i = 0; i < size; i++)
+  if (size > 0)
     {
-      table[images[i] - 1 + local->total_num_images * this_image.image_num]++;
-      pthread_cond_signal (&si->triggers[images[i] - 1]);
+      for (i = 0; i < size; i++)
+       {
+         table[images[i] - 1 + local->total_num_images * this_image.image_num]++;
+         pthread_cond_signal (&si->triggers[images[i] - 1]);
+       }
+      for (;;)
+       {
+         done = 1;
+         for (i = 0; i < size; i++)
+           done &= si->table[images[i] - 1
+                             + this_image.image_num * local->total_num_images]
+             == si->table[this_image.image_num
+                          + (images[i] - 1) * local->total_num_images];
+         if (done)
+           break;
+         wait_table_cond (si, &si->triggers[this_image.image_num]);
+       }
     }
-  for (;;)
+  else
     {
-      done = 1;
+      size = local->total_num_images;
       for (i = 0; i < size; i++)
-       done &= si->table[images[i] - 1
-                         + this_image.image_num * local->total_num_images]
-               == si->table[this_image.image_num
-                            + (images[i] - 1) * local->total_num_images];
-      if (done)
-       break;
-      wait_table_cond (si, &si->triggers[this_image.image_num]);
+       {
+         table[i + local->total_num_images * this_image.image_num]++;
+         pthread_cond_signal (&si->triggers[i]);
+       }
+      for (;;)
+       {
+         done = 1;
+         for (i = 0; i < size; i++)
+           done &= si->table[i + this_image.image_num * local->total_num_images]
+             == si->table[this_image.image_num
+                          + i * local->total_num_images];
+         if (done)
+           break;
+         wait_table_cond (si, &si->triggers[this_image.image_num]);
+       }
     }
   unlock_table (si);
 }
index 59946434da5851a01b9ecf3172746756be4a3922..6b46a3c51b13e8bfd718d4a9919e941af168fd3f 100644 (file)
@@ -51,7 +51,7 @@ internal_proto (sync_iface_init);
 void sync_all (sync_iface *);
 internal_proto (sync_all);
 
-void sync_table (sync_iface *, int *, size_t);
+void sync_table (sync_iface *, int *, int);
 internal_proto (sync_table);
 
 #endif
index 05ee838c2434c4868f7dc971e89746e9c9c8b284..e92f617260caad8066d3f6216fb5e5809783531f 100644 (file)
@@ -63,7 +63,7 @@ export_proto (cas_coarray_num_images);
 void cas_coarray_sync_all (int *);
 export_proto (cas_coarray_sync_all);
 
-void cas_sync_images (size_t, int *, int *, char *, size_t);
+void cas_sync_images (int, int *, int *, char *, size_t);
 export_proto (cas_sync_images);
 
 void cas_lock (void *);
@@ -250,7 +250,7 @@ cas_coarray_sync_all (int *stat)
 }
 
 void
-cas_sync_images (size_t s, int *images, int *stat, char *error,
+cas_sync_images (int s, int *images, int *stat, char *error,
                 size_t err_size)
 {
   STAT_ERRMSG_ENTRY_CHECK (stat, error, err_size);