source: CIVL/text/include/civlmpi.cvl@ 8a50139

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

fix a little bug

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

  • Property mode set to 100644
File size: 3.4 KB
Line 
1#ifdef __CIVL_CIVLMPI__
2#else
3#define __CIVL_CIVLMPI__
4
5#include <civlc.h>
6#include <concurrency.cvh>
7#include <comm.cvh>
8#include <bundle.cvh>
9#include <mpi.h>
10#include <civlmpi.cvh>
11
12/**************************** Duplicated Part *************************************/
13/* Duplicated definition with the same struct in mpi.h.
14 The reason of this duplication is to make civlmpi.cvl
15 independent with mpi.cvl. */
16typedef struct MPI_Comm {
17 $comm p2p; // point-to-point communication
18 $comm col; // collective communication
19 $barrier barrier;
20 __MPI_Sys_status__ status;
21}MPI_Comm;
22
23/* Definition of CMPI_Gcomm (CMPI_Gcomm has a type of __CMPI_Gcomm)
24 and MPI_Comm */
25struct CMPI_Gcomm {
26 $gcomm p2p; // point-to-point communication
27 $gcomm col; // collective communication
28 $gbarrier gbarrier;
29};
30
31/****************************** Helper Functions **********************************/
32int sizeofDatatype(MPI_Datatype datatype) {
33 switch (datatype) {
34 case MPI_INT:
35 return sizeof(int);
36 case MPI_FLOAT:
37 return sizeof(float);
38 case MPI_DOUBLE:
39 return sizeof(double);
40 case MPI_CHAR:
41 return sizeof(char);
42 case MPI_BYTE:
43 return sizeof(char); // char is always one byte ?
44 case MPI_SHORT:
45 return sizeof(short);
46 case MPI_LONG:
47 return sizeof(long);
48 case MPI_LONG_DOUBLE:
49 return sizeof(long double);
50 case MPI_LONG_LONG_INT:
51 return sizeof(long long int);
52 case MPI_LONG_LONG:
53 return sizeof(long long);
54 case MPI_UNSIGNED_LONG_LONG:
55 return sizeof(unsigned long long);
56 default:
57 $assert 0 : "Unreachable";
58 }
59}
60
61/************************** MPI LIB Implementations *******************************/
62CMPI_Gcomm CMPI_Gcomm_create($scope scope, int size) {
63 CMPI_Gcomm result;
64
65 result.p2p = $gcomm_create(scope, size);
66 result.col = $gcomm_create(scope, size);
67 result.gbarrier = $gbarrier_create(scope, size);
68 return result;
69}
70
71void CMPI_Gcomm_destroy(CMPI_Gcomm gc) {
72 $gcomm_destroy(gc.p2p);
73 $gcomm_destroy(gc.col);
74 $gbarrier_destroy(gc.gbarrier);
75}
76
77MPI_Comm CMPI_Comm_create($scope scope, CMPI_Gcomm gc, int rank) {
78 MPI_Comm result;
79
80 result.p2p = $comm_create(scope, gc.p2p, rank);
81 result.col = $comm_create(scope, gc.col, rank);
82 result.barrier = $barrier_create(scope, gc.gbarrier, rank);
83 result.status = __UNINIT;
84 return result;
85}
86
87void CMPI_Comm_destroy(MPI_Comm comm) {
88 $comm_destroy(comm.p2p);
89 $comm_destroy(comm.col);
90 $barrier_destroy(comm.barrier);
91}
92
93int __MPI_Init(MPI_Comm *comm) {
94 comm->status = __INIT;
95 return 0;
96}
97
98int __MPI_Finalize(MPI_Comm *comm) {
99 comm->status = __FINALIZED;
100 return 0;
101}
102
103int CMPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
104 int tag, $comm comm) {
105 if (dest >= 0) {
106 int size = count*sizeofDatatype(datatype);
107 int place = $comm_place(comm);
108 $message out = $message_pack(place, dest, tag, buf, size);
109 $comm_enqueue(comm, out);
110 }
111 return 0;
112}
113
114int CMPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
115 int tag, $comm comm, MPI_Status *status) {
116 if (source >= 0 || source == MPI_ANY_SOURCE) {
117 $message in = $comm_dequeue(comm, source, tag);
118 int size = count*sizeofDatatype(datatype);
119
120 $message_unpack(in, buf, size);
121 if (status != MPI_STATUS_IGNORE) {
122 status->size = $message_size(in);
123 status->MPI_SOURCE = $message_source(in);
124 status->MPI_TAG = $message_tag(in);
125 status->MPI_ERROR = 0;
126 }
127 }
128 return 0;
129}
130#endif
131
Note: See TracBrowser for help on using the repository browser.