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