source: CIVL/examples/languageFeatures/bundleTest.cvl@ dfb0fef

1.23 2.0 main test-branch
Last change on this file since dfb0fef was a7065e4, checked in by Ziqing Luo <ziqing@…>, 12 years ago

new exmaples for bundle pack and unpack

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

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[a7065e4]1/* Testing for bundle pack and unpack which invloves a flexible way of
2 reading and writing arrays. This example may still not cover all possible
3 cases. Anyone can add more send and receive pairs for different cases.
4 */
5#include <civlc.h>
6#include <mpi.h>
7
8CMPI_Gcomm Gcomm;
9$input int N;
10$input int inputs1[3][N];
11$input int inputs2[N][3];
12$assume N > 4;
13void main(){
14 /* Process function */
15 void Process(int i){
16 MPI_Comm comm = CMPI_Comm_create($here, Gcomm, i);
17 int rank;
18
19 __MPI_Init(&comm);
20 MPI_Comm_rank(comm, &rank);
21 /* In total 2 processes, 0 sends and 1 receives */
22 if (rank == 0){
23 int integerObj = 1;
24 int * p;
25 int ** pp;
26 int a3d[3][4][5];
27 int counter = 0;
28
29 //Initialization of message data
30 p = (int *)$malloc($root, sizeof(int) * 4);
31 pp = (int **)$malloc($root, sizeof(int *) * 4);
32 for(int i=0; i<4; i++){
33 p[i] = i;
34 pp[i] = (int *)$malloc($root, sizeof(int) * 2);
35 for(int j=0; j<2; j++)
36 pp[i][j] = i * 4 + j;
37 }
38 //p -> p[4]; pp -> pp[4][2];
39 for(int i=0; i<3; i++)
40 for(int j=0; j<4; j++)
41 for(int k=0; k<5; k++)
42 a3d[i][j][k] = counter++;
43
44 // send integer object "1"
45 MPI_Send(&integerObj, 1, MPI_INT, 1, 0, comm);
46 // send p[0], p[1] and p[2] with values "0" ,"1" and "2"
47 MPI_Send(p, 3, MPI_INT, 1, 0, comm);
48 // send pp[1][0], pp[1][1] with values "4" and "5"
49 MPI_Send(pp[1], 2, MPI_INT, 1, 0, comm);
50 // send "23...30"
51 MPI_Send(&a3d[1][0][3], 8, MPI_INT, 1, 0, comm);
52 // send "23...30" again
53 MPI_Send(&a3d[1][0][3], 8, MPI_INT, 1, 0, comm);
54 // send inputs2[1][1] and inputs2[1][2]
55 MPI_Send(&inputs2[1][1], 2, MPI_INT, 1, 0, comm);
56 // send inputs1[0][0]...inputs1[0][3]
57 MPI_Send(inputs1[0], 4, MPI_INT, 1, 0, comm);
58
59 $free(p);
60 for(int i=0; i<4; i++)
61 $free(pp[i]);
62 $free(pp);
63 }
64 else{
65 int integerObj;
66 int * buf;
67 int a4d[2][2][2][2];
68
69 buf = (int *)$malloc($root, sizeof(int) * 8);
70 MPI_Recv(&integerObj, 1, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
71 $assert(integerObj == 1, "first assertion");
72
73 MPI_Recv(buf, 3, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
74 $assert((buf[0] == 0 && buf[1] == 1 && buf[2] == 2), "second assertion");
75
76 MPI_Recv(buf, 2, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
77 $assert((buf[0] == 4 && buf[1] == 5), "third assertion");
78
79 MPI_Recv(&a4d[0][1][1], 8, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
80 for(int i=0; i<8; i++)
81 $assert(*(&a4d[0][1][1][0] + i) == (23 + i), "forth assertion");
82
83 // pointer type is different from the previous one
84 MPI_Recv(a4d[0][1][1], 8, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
85 for(int i=0; i<8; i++)
86 $assert(*(&a4d[0][1][1][0] + i) == (23 + i), "fifth assertion");
87
88 MPI_Recv((buf+1), 2, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
89 for(int i=0; i<2; i++)
90 $assert(*(buf + 1 + i) == inputs2[1][i+1], "sixth assertion");
91
92 MPI_Recv((buf+1), 8, MPI_INT, 0, 0, comm, MPI_STATUS_IGNORE);
93 for(int i=0; i<4; i++)
94 $assert(*(buf + 1 + i) == inputs1[0][i], "seventh assertion");
95
96 $free(buf);
97 }
98 CMPI_Comm_destroy(comm);
99 __MPI_Finalize(&comm);
100 }
101
102 $proc procs[2];
103
104 Gcomm = CMPI_Gcomm_create($root, 2);
105 for(int i=0; i<2; i++)
106 procs[i] = $spawn Process(i);
107
108 for(int i=0; i<2; i++)
109 $wait(procs[i]);
110 CMPI_Gcomm_destroy(Gcomm);
111}
Note: See TracBrowser for help on using the repository browser.