source: CIVL/examples/languageFeatures/communicatorFeatures.cvl@ c0d806d

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

add implementation of empty message in Libcivlc

add a test for commFeatures in languageFeatures.java

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

  • Property mode set to 100644
File size: 2.5 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
52 hasMessage = $comm_probe(myComm, left, TAG);
53 comm_size = $comm_size(myComm);
54 comm_place = $comm_place(myComm);
55 printf("hasMessage is %s\n", hasMessage);
56 printf("comm_size is %d\n", comm_size);
57 printf("comm_place is %d\n", comm_place);
58 matchedMessage = $comm_seek(myComm, left, TAG);
59 printf("matchedMessage is %s\n", matchedMessage);
60
61 in = $comm_dequeue(myComm, left, TAG);
62 $message_unpack(in, &y, sizeof(int));
63 $assert(y==left);
64 out = $message_pack(rank, right, TAG, &x, sizeof(int));
65 $comm_enqueue(myComm, out);
66 }
67 i++;
68 }
69}
70
71void main() {
72 $proc procs[NPROCS];
73
74 for (int i=0; i<NPROCS; i++)
75 procs[i] = $spawn MPI_Process(i);
76 MPI_COMM_WORLD = $gcomm_create($here, NPROCS);
77 initialized = $true;
78 for (int i=0; i<NPROCS; i++)
79 $wait(procs[i]);
80}
Note: See TracBrowser for help on using the repository browser.