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

1.23 2.0 main test-branch
Last change on this file since e1be4d3 was 20d2740, checked in by Stephen Siegel <siegel@…>, 13 years ago

Worked with Tim to get first message-passing example up. Cleaned up concurrency tests somewhat.

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

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