main
| Rev | Line | |
|---|
| [aad342c] | 1 | #include<assert.h>
|
|---|
| 2 | #include<mpi.h>
|
|---|
| 3 | #include<civl-mpi.cvh>
|
|---|
| 4 | #include<stdio.h>
|
|---|
| 5 | #pragma CIVL ACSL
|
|---|
| 6 | $input int in;
|
|---|
| 7 | $input int _mpi_nprocs = 2;
|
|---|
| 8 | $assume(in > 0);
|
|---|
| 9 | MPI_Comm comm = MPI_COMM_WORLD;
|
|---|
| 10 | int rank;
|
|---|
| 11 |
|
|---|
| 12 | /* starts from a simple clause,
|
|---|
| 13 | consequent \mpi_collective blocks, not nested: */
|
|---|
| 14 | /*@ requires x == 0;
|
|---|
| 15 | @ \mpi_collective(comm, BOTH):
|
|---|
| 16 | @ requires x == 0;
|
|---|
| 17 | @ ensures x == 1;
|
|---|
| 18 | @ \mpi_collective(comm, BOTH):
|
|---|
| 19 | @ ensures x == 1;
|
|---|
| 20 | @*/
|
|---|
| 21 | int gimmeOne(int x)
|
|---|
| 22 | {
|
|---|
| 23 | return 1 + x;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | /* starts from a \mpi_collective block: */
|
|---|
| 27 | /*@
|
|---|
| 28 | @ \mpi_collective(comm, BOTH):
|
|---|
| 29 | @ requires x == 0;
|
|---|
| 30 | @ ensures x == 1;
|
|---|
| 31 | @ \mpi_collective(comm, BOTH):
|
|---|
| 32 | @ ensures x == 1;
|
|---|
| 33 | @*/
|
|---|
| 34 | int gimmeTwo(int x)
|
|---|
| 35 | {
|
|---|
| 36 | return 2 + x;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | /* behaviors in a \mpi_collective block: */
|
|---|
| 40 | /*@
|
|---|
| 41 | @ \mpi_collective(comm, BOTH):
|
|---|
| 42 | @ requires x == 0;
|
|---|
| 43 | @ ensures x == 1;
|
|---|
| 44 | @ behavior x_gt_0:
|
|---|
| 45 | @ assumes x >= 0;
|
|---|
| 46 | @ requires x != 4;
|
|---|
| 47 | @ ensures x != 5;
|
|---|
| 48 | @ \mpi_collective(comm, BOTH):
|
|---|
| 49 | @ ensures x == 1;
|
|---|
| 50 | @*/
|
|---|
| 51 | int gimmeThree(int x)
|
|---|
| 52 | {
|
|---|
| 53 | return 3 + x;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | int main(int argc, char * argv[]) {
|
|---|
| 57 | int x;
|
|---|
| 58 |
|
|---|
| 59 | MPI_Init(&argc, &argv);
|
|---|
| 60 | MPI_Comm_rank(comm, &rank);
|
|---|
| 61 | if(rank == 1)
|
|---|
| 62 | MPI_Send(&rank, 1, MPI_INT, 0, 0, comm);
|
|---|
| 63 | x = gimmeOne(in);
|
|---|
| 64 | if(rank == 0)
|
|---|
| 65 | MPI_Recv(&x, 1, MPI_INT, 1, 0, comm, MPI_STATUS_IGNORE);
|
|---|
| 66 | MPI_Finalize();
|
|---|
| 67 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.