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

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

civlmpi and mpi routines are modified for new scheme of MPI_Sys_status

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1754 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_Comm;
21
22/* Definition of CMPI_Gcomm (CMPI_Gcomm has a type of __CMPI_Gcomm)
23 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 return result;
83}
84
85void CMPI_Comm_destroy(MPI_Comm comm) {
86 $comm_destroy(comm.p2p);
87 $comm_destroy(comm.col);
88 $barrier_destroy(comm.barrier);
89}
90
91int __MPI_Init(void) {
92 CMPI_Set_status(__INIT);
93 return 0;
94}
95
96int __MPI_Finalize(void) {
97 CMPI_Set_status(__FINALIZED);
98 return 0;
99}
100
101int CMPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
102 int tag, $comm comm) {
103 if (dest >= 0) {
104 int size = count*sizeofDatatype(datatype);
105 int place = $comm_place(comm);
106 $message out = $message_pack(place, dest, tag, buf, size);
107 $comm_enqueue(comm, out);
108 }
109 return 0;
110}
111
112int CMPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
113 int tag, $comm comm, MPI_Status *status) {
114 if (source >= 0 || source == MPI_ANY_SOURCE) {
115 $message in = $comm_dequeue(comm, source, tag);
116 int size = count*sizeofDatatype(datatype);
117
118 $message_unpack(in, buf, size);
119 if (status != MPI_STATUS_IGNORE) {
120 status->size = $message_size(in);
121 status->MPI_SOURCE = $message_source(in);
122 status->MPI_TAG = $message_tag(in);
123 status->MPI_ERROR = 0;
124 }
125 }
126 return 0;
127}
128#endif
129
Note: See TracBrowser for help on using the repository browser.