source: CIVL/examples/messagePassing/ring.cvl@ c19cfd5

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

cleaned up examples and tests.

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

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