source: CIVL/examples/messagePassing/mp_root2.cvh@ 5feb8e1

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

implemented assert statements with printing functionality; since $assert is redefined as a function in civlc.h, the translation in FunctionTranslator is changed and all examples using $assert is updated accordingly; translates assert() which is defined in assert.h into an assert statement; fixed warnings in mpi executor.

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

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#define MPI_ANY_SOURCE $COMM_ANY_SOURCE
2#define MPI_ANY_TAG $COMM_ANY_TAG
3typedef $comm *MPI_Comm;
4$input int NPROCS;
5$proc __procs[NPROCS];
6_Bool __start = 0;
7$comm __MPI_Comm_World;
8MPI_Comm MPI_COMM_WORLD = &__MPI_Comm_World;
9
10typedef int MPI_Datatype;
11
12#define MPI_INT 1
13#define MPI_DOUBLE 2
14#define MPI_FLOAT 3
15#define MPI_CHAR 4
16
17struct __MPI_Status {
18 int MPI_SOURCE;
19 int MPI_TAG;
20 int MPI_ERROR;
21 int size;
22};
23
24typedef struct __MPI_Status MPI_Status;
25
26MPI_Status __MPI_Status_ignore;
27
28MPI_Status *MPI_STATUS_IGNORE = &__MPI_Status_ignore;
29
30int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype,
31 int *count) {
32 int size;
33
34 switch (datatype) {
35 case MPI_INT:
36 size = sizeof(int);
37 break;
38 case MPI_FLOAT:
39 size = sizeof(float);
40 break;
41 case MPI_DOUBLE:
42 size = sizeof(double);
43 break;
44 case MPI_CHAR:
45 size = sizeof(char);
46 break;
47 default:
48 printf("Unsupported datatype %d\n", datatype);
49 $assert($false);
50 }
51 $assert(status->size % size == 0);
52 *count = status->size / size;
53 return 0;
54}
55
56void MPI_Process (int __rank);
57
58void init() {
59 for (int i=0; i<NPROCS; i++)
60 __procs[i] = $spawn MPI_Process(i);
61 __MPI_Comm_World = $comm_create(NPROCS, __procs);
62 __start=1;
63}
64
65void finalize() {
66 for (int i=0; i<NPROCS; i++)
67 $wait __procs[i];
68}
69
70void main() {
71 $atomic{
72 init();
73 finalize();
74 }
75}
Note: See TracBrowser for help on using the repository browser.