Performs a barrier operation on a subset of processing elements (PEs).
#include <shmem.h> void shmem_barrier(int PE_start, int logPE_stride, int PE_size, long *pSync);
shmem_barrier is a collective synchronization routine. Control returns from shmem_barrier after all PEs in the active set (specified by PE_start, logPE_stride, and PE_size) have called shmem_barrier
As with all SHMEM collective routines, each of these routines assumes that only PEs in the active set call the routine. If a PE not in the active set calls a SHMEM collective routine, undefined behavior results. The values of arguments PE_start, logPE_stride, and PE_size must be equal on all PEs in the active set. And, the same work array, pSync, must be passed in to all PEs in the active set.
shmem_barrier also ensures all the previously issued local stores and remote updates done by any of the PE in the active set are finished before returning from the function. The same pSync array can be reused on consecutive shmem_barrier calls if they have the same active set.
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <shmem.h> int main (int argc, char* argv[]) { int total_tasks = -1; int my_task = -1; start_pes(0); total_tasks = _num_pes(); if (total_tasks <= 0) { printf("FAILED\n"); exit(1); } else { printf("number of pes is %d\n", total_tasks); } if (total_tasks < 2 || total_tasks % 2) { printf("FAILED: The number of pes should be an even number. (at least 2)\n"); exit(1); } my_task = _my_pe(); if (my_task < 0){ printf("FAILED\n"); exit(1); } else { printf("my pe id is %d\n", my_task); } printf("my pid is %d\n", getpid()); // Every element of pSync must be initialized to 0 before any of the PEs in the active // set enter shmem_barrier the first time long pSync[_SHMEM_BARRIER_SYNC_SIZE]; pSync[0] = 0; if (my_task%2 == 0) { // even tasks call shmem_barrier shmem_barrier(0, 1, total_tasks/2, pSync); } else { // odd tasks call shmem_barrier shmem_barrier(1, 1, total_tasks/2, pSync); } shmem_barrier_all(); printf("PASSED\n"); return 0; }
Subroutines: shmem_barrier_all