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
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;
[9ba2959]15$gcomm 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;
[9ba2959]23 $comm myComm;
[69bf2e6]24
25 $when (initialized);
[9ba2959]26 myComm = $comm_create($here, MPI_COMM_WORLD, rank);
[69bf2e6]27 while (i<N) {
28 if (rank%2==0) { // send first, then recv
29 out = $message_pack(rank, right, TAG, &x, sizeof(int));
[9ba2959]30 $comm_enqueue(myComm, out);
31 in = $comm_dequeue(myComm, left, TAG);
[69bf2e6]32 $message_unpack(in, &y, sizeof(int));
33 $assert(y==left);
34 } else { // recv first, then send
[9ba2959]35 in = $comm_dequeue(myComm, left, TAG);
[69bf2e6]36 $message_unpack(in, &y, sizeof(int));
37 $assert(y==left);
38 out = $message_pack(rank, right, TAG, &x, sizeof(int));
[9ba2959]39 $comm_enqueue(myComm, out);
[69bf2e6]40 }
41 i++;
42 }
43}
[20d2740]44
[69bf2e6]45void main() {
46 $proc procs[NPROCS];
47
48 for (int i=0; i<NPROCS; i++)
49 procs[i] = $spawn MPI_Process(i);
[9ba2959]50 MPI_COMM_WORLD = $gcomm_create($here, NPROCS);
[69bf2e6]51 initialized = $true;
52 for (int i=0; i<NPROCS; i++)
[a82987f]53 $wait(procs[i]);
[20d2740]54}
Note: See TracBrowser for help on using the repository browser.