source: CIVL/examples/concurrency/ring.cvl@ 4e86cdd

1.23 2.0 main test-branch
Last change on this file since 4e86cdd was 3ff27cf, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

updated examples since $assert/$assume has been changed to functions; fixed the model builder for the new side-effect remover.

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

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <civlc.cvh>
2/* Create NPROCS processes. Have them exchange data in a cycle.
3 * Command line verification example:
4 * civl verify -inputNPROCS_BOUND=10 -inputN_BOUND=5 ring.cvl
5 */
6#include<comm.cvh>
7#define TAG 0
8
9$input int NPROCS_BOUND = 10; // upper bound of the number of MPI processes
10$input int NPROCS; // number of MPI processes
11$assume(0 < NPROCS && NPROCS <= NPROCS_BOUND);
12$input int N_BOUND = 5; // upper bound on number times to loop
13$input int N; // number of times to loop
14$assume(0 < N && N <= N_BOUND);
15$gcomm GCOMM_WORLD = $gcomm_create($here, NPROCS); // global comm object
16
17void MPI_Process (int rank) {
18 $comm comm = $comm_create($here, GCOMM_WORLD, rank);
19 int left = (rank+NPROCS-1)%NPROCS;
20 int right = (rank+NPROCS+1)%NPROCS;
21 int x=rank, y; // send a message from x, recv into y
22 $message in, out;
23
24 for (int i=0; i<N; i++) {
25 if (rank%2==0) { // send first, then recv
26 out = $message_pack(rank, right, TAG, &x, sizeof(int));
27 $comm_enqueue(comm, out);
28 in = $comm_dequeue(comm, left, TAG);
29 $message_unpack(in, &y, sizeof(int));
30 $assert((y==left));
31 } else { // recv first, then send
32 in = $comm_dequeue(comm, left, TAG);
33 $message_unpack(in, &y, sizeof(int));
34 $assert((y==left));
35 out = $message_pack(rank, right, TAG, &x, sizeof(int));
36 $comm_enqueue(comm, out);
37 }
38 }
39 $comm_destroy(comm);
40}
41
42void main() {
43 $proc procs[NPROCS];
44
45 for (int i=0; i<NPROCS; i++)
46 procs[i] = $spawn MPI_Process(i);
47 for (int i=0; i<NPROCS; i++)
48 $wait(procs[i]);
49 $gcomm_destroy(GCOMM_WORLD);
50}
Note: See TracBrowser for help on using the repository browser.