source: CIVL/examples/languageFeatures/communicatorFeatures.cvl@ 9c391c1

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

communicatorFeatures.cvl added into languageFeatures folder which tests functons include:
comm_seek
comm_probe
comm_size
comm_place

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

  • Property mode set to 100644
File size: 2.1 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#include<stdio.h>
7#define TAG 0
8
9$input int NPROCS_BOUND; // upper bound of the number of mpi processes
10$input int NPROCS; // number of mpi processes
11$assume 0 < NPROCS && NPROCS <= NPROCS_BOUND;
12$input int N_BOUND; // upper bound on number times to loop
13$input int N; // number of times to loop
14$assume 0 < N && N <= N_BOUND;
15_Bool initialized = $false;
16$gcomm MPI_COMM_WORLD; // the default MPI communicator
17
18void MPI_Process (int rank) {
19 int left = (rank+NPROCS-1)%NPROCS;
20 int right = (rank+NPROCS+1)%NPROCS;
21 int i=0;
22 int x=rank, y; // send a message from x, recv into y, for checking
23 $message in, out;
24 $comm myComm;
25 //test variables
26 int comm_size;
27 int comm_place;
28 _Bool hasMessage;
29 $message matchedMessage;
30
31 $when (initialized);
32 myComm = $comm_create($here, MPI_COMM_WORLD, rank);
33 while (i<N) {
34 if (rank%2==0) { // send first, then recv
35 out = $message_pack(rank, right, TAG, &x, sizeof(int));
36 $comm_enqueue(myComm, out);
37
38 hasMessage = $comm_probe(myComm, left, TAG);
39 comm_size = $comm_size(myComm);
40 comm_place = $comm_place(myComm);
41 printf("hasMessage is %s\n", hasMessage);
42 printf("comm_size is %d\n", comm_size);
43 printf("comm_place is %d\n", comm_place);
44 matchedMessage = $comm_seek(myComm, left, TAG);
45 printf("matchedMessage is %s\n", matchedMessage);
46
47 in = $comm_dequeue(myComm, left, TAG);
48 $message_unpack(in, &y, sizeof(int));
49 $assert(y==left);
50 } else { // recv first, then send
51 in = $comm_dequeue(myComm, left, TAG);
52 $message_unpack(in, &y, sizeof(int));
53 $assert(y==left);
54 out = $message_pack(rank, right, TAG, &x, sizeof(int));
55 $comm_enqueue(myComm, out);
56 }
57 i++;
58 }
59}
60
61void main() {
62 $proc procs[NPROCS];
63
64 for (int i=0; i<NPROCS; i++)
65 procs[i] = $spawn MPI_Process(i);
66 MPI_COMM_WORLD = $gcomm_create($here, NPROCS);
67 initialized = $true;
68 for (int i=0; i<NPROCS; i++)
69 $wait(procs[i]);
70}
Note: See TracBrowser for help on using the repository browser.