Lesson 3: An Introduction to Barriers Continued
Hold on . . . do we really have to wait for all of the data to be moved? What if we only care about one element before continuing on? I don't know if that went through your mind, but, you can at least pretend it did!If you recall from the last lesson, there were barriers that included a subset or whole entire set of PEs and barriers that waited for data on one PE to change. We are now going to look at the latter. In previous versions of openSHmem, there were both shmem_wait and shmem_wait_until. Now, shmem_wait has been deprecated and we have only shmem_wait_until to work with (but don't worry, it encompasses shmem_wait).
Barriers/Synchronization until data has changed (only concerned with one PE):
- void shmem_<TYPENAME>_wait_until(TYPE *ivar, int cmp, TYPE cmp_value)
- arg0 - *ivar: pointer to an integer value that is remotely availabe
- arg1 - cmp: comparison operator
- arg2 - cmp_value: integer value to compare ivar to
| SHMEM_CMP_EQ | a = b |
| SHMEM_CMP_NE | a != b |
| SHMEM_CMP_LT | a < b |
| SHMEM_CMP_LE | a <= b |
| SHMEM_CMP_GT | a > b |
| SHMEM_CMP_GE | a >= b |
//wait_until.c
#include <stdio.h>
#include <shmem.h>
int main(){
int my_pe, num_pe; //declare variables for both pe id of processor
//and the number of pes
shmem_init();
num_pe = shmem_n_pes(); //obtain the number of pes that can be used
my_pe = shmem_my_pe(); //obtain the pe id number
static int new = 5;
if (my_pe == 0){
int old = new;
//wait until the value in new changes due to PE 1 placing value 10 in it
shmem_int_wait_until(&new, shmem_cmp_ne, old);
printf("new value: %d versus old value: %d\n", new, old);
}
if (my_pe == 1){
int to_put = 10;
shmem_int_p(&new, to_put, 0);
}
shmem_finalize();
return 0;
}
To compile:
oshcc wait_until.c -o wait_until
To run:
oshrun -np 2 wait_until
