1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /* Create nprocs processes. Have them exchange data in a cycle.
|
|---|
| 2 | * Command line execution:
|
|---|
| 3 | * civl verify -por=new -inputNPROCS=3 ring3.cvl -simplify=false
|
|---|
| 4 | */
|
|---|
| 5 | #include<civlc.h>
|
|---|
| 6 | #define TAG 0
|
|---|
| 7 |
|
|---|
| 8 | $input int NPROCS;
|
|---|
| 9 | $input int NB;
|
|---|
| 10 | $assume 1 < NPROCS && NPROCS <= NB;
|
|---|
| 11 | _Bool initialized = $false;
|
|---|
| 12 | $comm MPI_COMM_WORLD;
|
|---|
| 13 |
|
|---|
| 14 | void MPI_Process (int rank) {
|
|---|
| 15 | double x=rank, y;
|
|---|
| 16 | $message in, out;
|
|---|
| 17 |
|
|---|
| 18 | $when (initialized);
|
|---|
| 19 | out = $message_pack(rank, (rank+1)%NPROCS, TAG, &x, sizeof(double));
|
|---|
| 20 | $comm_enqueue(&MPI_COMM_WORLD, out);
|
|---|
| 21 | in = $comm_dequeue(&MPI_COMM_WORLD, (rank+NPROCS-1)%NPROCS, rank, TAG);
|
|---|
| 22 | $message_unpack(in, &y, sizeof(double));
|
|---|
| 23 |
|
|---|
| 24 | $assert(y==(rank+NPROCS-1)%NPROCS);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | void main() {
|
|---|
| 28 | $proc procs[NPROCS];
|
|---|
| 29 |
|
|---|
| 30 | $atomic{
|
|---|
| 31 | for (int i=0; i<NPROCS; i++)
|
|---|
| 32 | procs[i] = $spawn MPI_Process(i);
|
|---|
| 33 | MPI_COMM_WORLD = $comm_create(NPROCS, procs);
|
|---|
| 34 | initialized = $true;
|
|---|
| 35 | }
|
|---|
| 36 | for (int i=0; i<NPROCS; i++)
|
|---|
| 37 | $wait procs[i];
|
|---|
| 38 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.