source: CIVL/examples/messagePassing/wildcard.cvl@ dfb0fef

1.23 2.0 main test-branch
Last change on this file since dfb0fef was e6b02c8, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

updates CIVL to use the new ABC FrontEnd. tests updated accordingly when necessary.

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

  • Property mode set to 100644
File size: 965 bytes
Line 
1#include <comm.cvh>
2#include <stdio.h>
3#include <mpi.h>
4
5$input int NPROCS;
6CMPI_Gcomm __MPI_COMM_WORLD;
7void MPI_Process(int place){
8
9 MPI_Comm MPI_COMM_WORLD = CMPI_Comm_create($here, __MPI_COMM_WORLD, place);
10 int nprocs, rank, msg;
11 MPI_Status status;
12
13 __MPI_Init(&MPI_COMM_WORLD);
14 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
15 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
16
17 if(rank != 0){
18 msg = rank;
19 MPI_Send(&msg, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
20 }
21 else{
22 int source;
23
24 msg = -1;
25 for(int i=1; i<NPROCS; i++){
26 MPI_Recv(&msg, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);
27 }
28 }
29
30 CMPI_Comm_destroy(MPI_COMM_WORLD);
31 printf("process %d terminates\n", rank);
32}
33
34void main(){
35
36 $proc procs[NPROCS];
37
38 __MPI_COMM_WORLD = CMPI_Gcomm_create($root, NPROCS);
39 for(int i=0; i<NPROCS; i++)
40 procs[i] = $spawn MPI_Process(i);
41 for(int i=0; i<NPROCS; i++)
42 $wait(procs[i]);
43
44 CMPI_Gcomm_destroy(__MPI_COMM_WORLD);
45}
Note: See TracBrowser for help on using the repository browser.