* [patch, shared memory coarray, committed] Fix SYNC IMAGES(*)
@ 2021-01-01 11:45 Thomas Koenig
0 siblings, 0 replies; only message in thread
From: Thomas Koenig @ 2021-01-01 11:45 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 546 bytes --]
Hi,
a rather obvious patch for SYNC IMAGES(*) failing because it
did not deal with a -1 argument.
Make SYNC IMAGES(*) work by handling size of -1 in library.
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.
[-- Attachment #2: p.txt --]
[-- Type: text/plain, Size: 4525 bytes --]
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
index 00000000000..c06b7631cdd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/caf-shared/sync_images_1.f90
@@ -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
index 00000000000..f1d63347291
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/caf-shared/sync_images_2.f90
@@ -0,0 +1,5 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+program main
+ sync images(*)
+end program main
diff --git a/libgfortran/caf_shared/sync.c b/libgfortran/caf_shared/sync.c
index 76612dc477d..71f7a34497a 100644
--- a/libgfortran/caf_shared/sync.c
+++ b/libgfortran/caf_shared/sync.c
@@ -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);
}
diff --git a/libgfortran/caf_shared/sync.h b/libgfortran/caf_shared/sync.h
index 59946434da5..6b46a3c51b1 100644
--- a/libgfortran/caf_shared/sync.h
+++ b/libgfortran/caf_shared/sync.h
@@ -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
diff --git a/libgfortran/caf_shared/wrapper.c b/libgfortran/caf_shared/wrapper.c
index 05ee838c243..e92f617260c 100644
--- a/libgfortran/caf_shared/wrapper.c
+++ b/libgfortran/caf_shared/wrapper.c
@@ -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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-01 11:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-01 11:45 [patch, shared memory coarray, committed] Fix SYNC IMAGES(*) Thomas Koenig
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).