source: CIVL/examples/library/civlc/communicatorFeatures.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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