source: CIVL/examples/contracts/wildcard_contract_bad.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 958 bytes
Line 
1/* wildcard_coassert_bad: A root process receives messages twice from
2 every other process using a wildcard receive. This program has a
3 data race-condition. */
4#include <mpi.h>
5#include <stdio.h>
6#include <civl-mpi.cvh>
7#define comm MPI_COMM_WORLD
8int size, rank, x;
9int root = 0;
10
11void recv(int iter)
12$requires {iter >= 0 && rank == 0}
13$ensures {$collective(comm) $true}
14{
15 for(int i = 1; i < size; i++)
16 MPI_Recv(&x, 1, MPI_INT, MPI_ANY_SOURCE, 0, comm, MPI_STATUS_IGNORE);
17 //$mpi_coassert(comm, x == iter);
18}
19
20void send(int msg)
21$ensures {$collective(comm) x@root == msg}
22{
23 MPI_Send(&msg, 1, MPI_INT, root, 0, comm);
24 printf("Proc:%d sends %d\n", rank, msg);
25 //$mpi_coassert(comm, x@root == msg);
26}
27
28int main(int argc, char * argv[]) {
29 MPI_Init(&argc, &argv);
30 MPI_Comm_rank(comm, &rank);
31 MPI_Comm_size(comm, &size);
32 for(int i = 0; i < 2; i++)
33 if(!rank)
34 recv(i);
35 else
36 send(i);
37 MPI_Finalize();
38 return 0;
39}
Note: See TracBrowser for help on using the repository browser.