source: CIVL/examples/messagePassing/ring3.cvl@ ee38d17

1.23 2.0 main test-branch
Last change on this file since ee38d17 was 68f2754, checked in by Stephen Siegel <siegel@…>, 12 years ago

Improving some comments, fixing old examples, deleted file
in tutorial that was wrongly committed.

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

  • Property mode set to 100644
File size: 840 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));
20 $comm_enqueue(comm, out);
21 in = $comm_dequeue(comm, dest, TAG);
22 $message_unpack(in, y, sizeof(int));
[68f2754]23 $free(x);
24 $free(y);
25 $comm_destroy(comm);
[9ca9cda]26}
27
28void main() {
[68f2754]29 // for (int i=0; i<2; i++) $spawn MPI_Process(i);
30 $parfor (int i : ($domain){0 .. 1}) MPI_Process(i);
31 $gcomm_destroy(GCOMM_WORLD);
[9ca9cda]32}
Note: See TracBrowser for help on using the repository browser.