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

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

change for new headers

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

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