source: CIVL/examples/messagePassing/ring.cvl@ 998356f

1.23 2.0 main test-branch
Last change on this file since 998356f was e6b02c8, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

updates CIVL to use the new ABC FrontEnd. tests updated accordingly when necessary.

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

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