source: CIVL/examples/concurrency/wildcard.cvl@ b0119b4

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since b0119b4 was d66b03b, checked in by Ziqing Luo <ziqing@…>, 10 years ago

got rid of $root

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

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[3ff27cf]1#include <civlc.cvh>
[82d7b5f]2#include <stdio.h>
3#include <mpi.h>
[3af26ac]4#include <civl-mpi.cvh>
[a96092d]5#include <assert.h>
[82d7b5f]6
[0baeebd]7$input int NPROCS = 5;
[ff51d87]8$mpi_gcomm __MPI_COMM_WORLD;
[d66b03b]9$scope root = $here;
10
[db66e7f]11void _mpi_process(int place){
[ff51d87]12 MPI_Comm MPI_COMM_WORLD = $mpi_comm_create($here, __MPI_COMM_WORLD, place);
[82d7b5f]13 int nprocs, rank, msg;
14 MPI_Status status;
[3dbda10d]15 $mpi_sys_status _mpi_status = __UNINIT;
[82d7b5f]16
[3dbda10d]17 $assert(_mpi_status == __UNINIT);
[ff51d87]18 $mpi_init();
[82d7b5f]19 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
21
22 if(rank != 0){
23 msg = rank;
24 MPI_Send(&msg, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
25 }
26 else{
27 int source;
28
29 msg = -1;
30 for(int i=1; i<NPROCS; i++){
31 MPI_Recv(&msg, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);
32 }
33 }
[ff51d87]34 $mpi_finalize();
35 $mpi_comm_destroy(MPI_COMM_WORLD);
[82d7b5f]36 printf("process %d terminates\n", rank);
37}
38
39void main(){
40
41 $proc procs[NPROCS];
42
[d66b03b]43 __MPI_COMM_WORLD = $mpi_gcomm_create(root, NPROCS);
[82d7b5f]44 for(int i=0; i<NPROCS; i++)
[db66e7f]45 procs[i] = $spawn _mpi_process(i);
[82d7b5f]46 for(int i=0; i<NPROCS; i++)
47 $wait(procs[i]);
48
[ff51d87]49 $mpi_gcomm_destroy(__MPI_COMM_WORLD);
[82d7b5f]50}
Note: See TracBrowser for help on using the repository browser.