source: CIVL/text/include/civlmpi.cvl@ fb58748

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

replenish SOME missing data type sizes

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

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