| 1 | /* Create 2 processes. Have them exchange data in a cycle.
|
|---|
| 2 | * Command line verification example:
|
|---|
| 3 | * civl verify ring3.cvl
|
|---|
| 4 | */
|
|---|
| 5 | #include<comm.cvh>
|
|---|
| 6 | #include<seq.cvh>
|
|---|
| 7 | #define TAG 0
|
|---|
| 8 |
|
|---|
| 9 | $gcomm GCOMMS[];
|
|---|
| 10 | $gcomm GCOMM_WORLD = $gcomm_create($here, 2); // global comm object
|
|---|
| 11 |
|
|---|
| 12 | $seq_init(&GCOMMS, 1, &GCOMM_WORLD);
|
|---|
| 13 | void MPI_Process (int rank) {
|
|---|
| 14 | $gcomm newgcomm;
|
|---|
| 15 | $comm comm = $comm_create($here, GCOMM_WORLD, rank);
|
|---|
| 16 | int dest = 1-rank;
|
|---|
| 17 | int *x, *y;
|
|---|
| 18 | $message in, out;
|
|---|
| 19 |
|
|---|
| 20 | x = (int*)$malloc($here, sizeof(int));
|
|---|
| 21 | y = (int*)$malloc($here, sizeof(int));
|
|---|
| 22 | *x = rank;
|
|---|
| 23 | if(rank) {
|
|---|
| 24 | newgcomm = $gcomm_create($root, 2);
|
|---|
| 25 | $seq_insert(&GCOMMS, 1, &newgcomm, 1);
|
|---|
| 26 | }
|
|---|
| 27 | out = $message_pack(rank, dest, TAG, x, sizeof(int));
|
|---|
| 28 | $choose {
|
|---|
| 29 | $when (1){
|
|---|
| 30 | $comm_enqueue(comm, out);
|
|---|
| 31 | in = $comm_dequeue(comm, dest, TAG);
|
|---|
| 32 | }
|
|---|
| 33 | $when (1){
|
|---|
| 34 | in = $comm_dequeue(comm, dest, TAG);
|
|---|
| 35 | $comm_enqueue(comm, out);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | $message_unpack(in, y, sizeof(int));
|
|---|
| 39 | $free(x);
|
|---|
| 40 | $free(y);
|
|---|
| 41 | $comm_destroy(comm);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | void main() {
|
|---|
| 45 | // for (int i=0; i<2; i++) $spawn MPI_Process(i);
|
|---|
| 46 | $parfor (int i : ($domain){0 .. 1}) MPI_Process(i);
|
|---|
| 47 | $gcomm_destroy(GCOMM_WORLD);
|
|---|
| 48 | }
|
|---|