source: CIVL/examples/concurrency/ring3.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: 993 bytes
RevLine 
[68f2754]1/* Create 2 processes. Have them exchange data in a cycle.
[9ca9cda]2 * Command line verification example:
[68f2754]3 * civl verify ring3.cvl
[9ca9cda]4 */
[e6b02c8]5#include<comm.cvh>
[9ca9cda]6#define TAG 0
7
8$gcomm GCOMM_WORLD = $gcomm_create($here, 2); // global comm object
9
10void MPI_Process (int rank) {
11 $comm comm = $comm_create($here, GCOMM_WORLD, rank);
12 int dest = 1-rank;
13 int *x, *y;
14 $message in, out;
15
16 x = (int*)$malloc($here, sizeof(int));
17 y = (int*)$malloc($here, sizeof(int));
18 *x = rank;
19 out = $message_pack(rank, dest, TAG, x, sizeof(int));
[08f1543]20 $choose {
21 $when (1){
22 $comm_enqueue(comm, out);
23 in = $comm_dequeue(comm, dest, TAG);
24 }
25 $when (1){
26 in = $comm_dequeue(comm, dest, TAG);
27 $comm_enqueue(comm, out);
28 }
29 }
[9ca9cda]30 $message_unpack(in, y, sizeof(int));
[68f2754]31 $free(x);
32 $free(y);
33 $comm_destroy(comm);
[9ca9cda]34}
35
36void main() {
[68f2754]37 // for (int i=0; i<2; i++) $spawn MPI_Process(i);
38 $parfor (int i : ($domain){0 .. 1}) MPI_Process(i);
[07f7630]39 $gcomm_destroy(GCOMM_WORLD, NULL);
[9ca9cda]40}
Note: See TracBrowser for help on using the repository browser.