source: CIVL/examples/messagePassing/ring3.cvl@ a2cdf97

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

fixed the bug for message passing programs. (that used bundle type to look for a communicator); added ring3.cvl for a simple mpi example modeled in CIVL.

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

  • Property mode set to 100644
File size: 866 bytes
Line 
1/* Create nprocs processes. Have them exchange data in a cycle.
2 * Command line execution:
3 * civl verify -por=new -inputNPROCS=3 ring3.cvl -simplify=false
4 */
5#include<civlc.h>
6#define TAG 0
7
8$input int NPROCS;
9_Bool initialized = $false;
10$comm MPI_COMM_WORLD;
11
12void MPI_Process (int rank) {
13 double x=rank, y;
14 $message in, out;
15
16 $when (initialized);
17 out = $message_pack(rank, (rank+1)%NPROCS, TAG, &x, sizeof(double));
18 $comm_enqueue(&MPI_COMM_WORLD, out);
19 in = $comm_dequeue(&MPI_COMM_WORLD, (rank+NPROCS-1)%NPROCS, rank, TAG);
20 $message_unpack(in, &y, sizeof(double));
21
22 $assert(y==(rank+NPROCS-1)%NPROCS);
23}
24
25
26void main() {
27 $proc procs[NPROCS];
28
29 for (int i=0; i<NPROCS; i++)
30 procs[i] = $spawn MPI_Process(i);
31 MPI_COMM_WORLD = $comm_create(NPROCS, procs);
32 initialized = $true;
33 for (int i=0; i<NPROCS; i++)
34 $wait procs[i];
35}
Note: See TracBrowser for help on using the repository browser.