source: CIVL/examples/messagePassing/ring.cvl@ 6f5cd7f

1.23 2.0 main test-branch
Last change on this file since 6f5cd7f was 9ba2959, checked in by Ziqing Luo <ziqing@…>, 12 years ago

Incomplete, commit for manchun to debug

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

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/* Create nprocs processes. Have them exchange data in a cycle.
2 * Command line execution:
3 * civl verify -inputNPROCS_BOUND=10 -inputN_BOUND=5 ring.cvl
4 */
5#include<civlc.h>
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_Bool initialized = $false;
15$gcomm MPI_COMM_WORLD; // the default MPI communicator
16
17void MPI_Process (int rank) {
18 int left = (rank+NPROCS-1)%NPROCS;
19 int right = (rank+NPROCS+1)%NPROCS;
20 int i=0;
21 int x=rank, y; // send a message from x, recv into y, for checking
22 $message in, out;
23 $comm myComm;
24
25 $when (initialized);
26 myComm = $comm_create($here, MPI_COMM_WORLD, rank);
27 while (i<N) {
28 if (rank%2==0) { // send first, then recv
29 out = $message_pack(rank, right, TAG, &x, sizeof(int));
30 $comm_enqueue(myComm, out);
31 in = $comm_dequeue(myComm, left, TAG);
32 $message_unpack(in, &y, sizeof(int));
33 $assert(y==left);
34 } else { // recv first, then send
35 in = $comm_dequeue(myComm, left, TAG);
36 $message_unpack(in, &y, sizeof(int));
37 $assert(y==left);
38 out = $message_pack(rank, right, TAG, &x, sizeof(int));
39 $comm_enqueue(myComm, out);
40 }
41 i++;
42 }
43}
44
45void main() {
46 $proc procs[NPROCS];
47
48 for (int i=0; i<NPROCS; i++)
49 procs[i] = $spawn MPI_Process(i);
50 MPI_COMM_WORLD = $gcomm_create($here, NPROCS);
51 initialized = $true;
52 for (int i=0; i<NPROCS; i++)
53 $wait(procs[i]);
54}
Note: See TracBrowser for help on using the repository browser.