source: CIVL/text/include/civlmpi.cvl@ 05ab4e3

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

get rid of mpi.h and mpi-common.h

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

  • Property mode set to 100644
File size: 3.0 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 default:
42 $assert 0 : "Unreachable";
43 }
44}
45
46/************************** MPI LIB Implementations *******************************/
47CMPI_Gcomm CMPI_Gcomm_create($scope scope, int size) {
48 CMPI_Gcomm result;
49
50 result.p2p = $gcomm_create(scope, size);
51 result.col = $gcomm_create(scope, size);
52 result.gbarrier = $gbarrier_create(scope, size);
53 return result;
54}
55
56void CMPI_Gcomm_destroy(CMPI_Gcomm gc) {
57 $gcomm_destroy(gc.p2p);
58 $gcomm_destroy(gc.col);
59 $gbarrier_destroy(gc.gbarrier);
60}
61
62MPI_Comm CMPI_Comm_create($scope scope, CMPI_Gcomm gc, int rank) {
63 MPI_Comm result;
64
65 result.p2p = $comm_create(scope, gc.p2p, rank);
66 result.col = $comm_create(scope, gc.col, rank);
67 result.barrier = $barrier_create(scope, gc.gbarrier, rank);
68 result.status = __UNINIT;
69 return result;
70}
71
72void CMPI_Comm_destroy(MPI_Comm comm) {
73 $comm_destroy(comm.p2p);
74 $comm_destroy(comm.col);
75 $barrier_destroy(comm.barrier);
76}
77
78int __MPI_Init(MPI_Comm *comm) {
79 comm->status = __INIT;
80 return 0;
81}
82
83int __MPI_Finalize(MPI_Comm *comm) {
84 comm->status = __FINALIZED;
85 return 0;
86}
87
88int CMPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
89 int tag, $comm comm) {
90 if (dest >= 0) {
91 int size = count*sizeofDatatype(datatype);
92 int place = $comm_place(comm);
93 $message out = $message_pack(place, dest, tag, buf, size);
94 $comm_enqueue(comm, out);
95 }
96 return 0;
97}
98
99int CMPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
100 int tag, $comm comm, MPI_Status *status) {
101 if (source >= 0 || source == MPI_ANY_SOURCE) {
102 $message in = $comm_dequeue(comm, source, tag);
103 int size = count*sizeofDatatype(datatype);
104
105 $message_unpack(in, buf, size);
106 if (status != MPI_STATUS_IGNORE) {
107 status->size = $message_size(in);
108 status->MPI_SOURCE = $message_source(in);
109 status->MPI_TAG = $message_tag(in);
110 status->MPI_ERROR = 0;
111 }
112 }
113 return 0;
114}
115#endif
116
Note: See TracBrowser for help on using the repository browser.