forked from parallella/parallella-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coprthr_mpi.h
234 lines (162 loc) · 5.89 KB
/
coprthr_mpi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* coprthr_mpi.h
*
* Copyright (c) 2014-2015 Brown Deer Technology, LLC. All Rights Reserved.
*
* This software was developed by Brown Deer Technology, LLC.
* For more information contact [email protected]
*
* This software is a preview licensed for non-commercial use only, may not be
* redistributed, and may not be reverse-engineered for the purpose of creating
* software of similar functionality. The full terms and conditions of the
* license may be found in 'LICENSE.txt' accompanying this file. Licensing
* questions may be directed to [email protected]
*
*/
/* DAR */
#ifndef __coprthr_mpi
#define __coprthr_mpi
/* Hack so fft-demo knows it included the right header */
#define __coprthr_mpi_fft
#include <coprthr.h>
#if defined(__coprthr_device__)
#ifdef __cplusplus
extern "C" {
#endif
extern int _local_mem_base;
int coprthr_tls_brk( void* addr);
void* coprthr_tls_sbrk( intptr_t increment );
typedef struct {
int rank;
int size;
int ndims;
int dims[2];
int coords[2];
int m_id;
void* m_mtx;
int m_src;
int m_tag;
int m_count;
void* m_adr;
void* m_buf;
size_t m_bufsize;
e_coreid_t coreid;
int row,col;
} _mpi_comm;
typedef _mpi_comm* mpi_comm_t;
int __mpi_init( _mpi_comm* comm, size_t bufsize );
#define mpi_init( pargc, bufsize ) \
_mpi_comm _MPI_COMM_THREAD; \
_mpi_comm* MPI_COMM_THREAD = &_MPI_COMM_THREAD; \
do { __mpi_init( MPI_COMM_THREAD, bufsize ); } while(0)
int __mpi_finalize( _mpi_comm* comm );
#define mpi_finalize() \
do { __mpi_finalize(MPI_COMM_THREAD); } while(0)
typedef int mpi_datatype_t;
#define MPI_CHAR 1
#define MPI_INT 4
#define MPI_FLOAT 4
#define MPI_DOUBLE 8
typedef int mpi_status_t;
int mpi_comm_rank( mpi_comm_t comm, int* rank);
int mpi_comm_size( mpi_comm_t comm, int* size);
int mpi_recv( void* buf, int count, mpi_datatype_t datatype, int source,
int tag, mpi_comm_t comm, mpi_status_t* status );
int mpi_send( void* buf, int count, mpi_datatype_t datatype, int dest,
int tag, mpi_comm_t comm );
int mpi_bcast( void* buf, int count, mpi_datatype_t datatype, int root,
mpi_comm_t comm );
int mpi_cart_create(mpi_comm_t comm_old, int ndims, const int dims[],
const int periods[], int reorder, mpi_comm_t* comm_cart
);
int mpi_comm_free( mpi_comm_t* comm);
int mpi_cart_coords( mpi_comm_t comm, int rank, int maxdims, int* coords);
int mpi_cart_shift( mpi_comm_t comm, int dir, int disp, int* rank_source,
int* rank_dest );
int mpi_sendrecv_replace( void* buf, int count, mpi_datatype_t datatype,
int dest, int sendtag, int source, int recvtag, mpi_comm_t comm,
mpi_status_t* status );
#define coprthr_mpi_init( pargc, bufsize ) mpi_init( pargc, bufsize )
#define coprthr_mpi_finalize() mpi_finalize()
typedef mpi_comm_t coprthr_mpi_comm_t;
typedef mpi_status_t coprthr_mpi_status_t;
typedef mpi_datatype_t coprthr_mpi_datatype_t;
int coprthr_mpi_comm_rank( coprthr_mpi_comm_t comm, int* rank);
int coprthr_mpi_comm_size( coprthr_mpi_comm_t comm, int* size);
int coprthr_mpi_recv( void* buf, int count, coprthr_mpi_datatype_t datatype,
int source, int tag, coprthr_mpi_comm_t comm,
coprthr_mpi_status_t* status );
int coprthr_mpi_send( void* buf, int count, coprthr_mpi_datatype_t datatype,
int dest, int tag, coprthr_mpi_comm_t comm );
int coprthr_mpi_bcast( void* buf, int count, coprthr_mpi_datatype_t datatype,
int root, coprthr_mpi_comm_t comm );
int coprthr_mpi_cart_create(coprthr_mpi_comm_t comm_old, int ndims,
const int dims[], const int periods[], int reorder,
coprthr_mpi_comm_t* comm_cart);
int coprthr_mpi_comm_free( coprthr_mpi_comm_t* comm);
int coprthr_mpi_cart_coords( coprthr_mpi_comm_t comm, int rank,
int maxdims, int* coords);
int coprthr_mpi_cart_shift( coprthr_mpi_comm_t comm, int dir, int disp,
int* rank_source, int* rank_dest );
int coprthr_mpi_sendrecv_replace( void* buf, int count,
coprthr_mpi_datatype_t datatype,
int dest, int sendtag, int source, int recvtag,
coprthr_mpi_comm_t comm, coprthr_mpi_status_t* status );
#ifdef COPRTHR_MPI_COMPAT
#define MPI_Init( pargc, bufsize ) mpi_init( pargc, bufsize )
#define MPI_Finalize() mpi_finalize()
typedef mpi_comm_t MPI_Comm;
typedef mpi_status_t MPI_Status;
typedef mpi_datatype_t MPI_Datatype;
int MPI_Comm_rank( MPI_Comm comm, int* rank);
int MPI_Comm_size( MPI_Comm comm, int* size);
int MPI_Recv( void* buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status* status );
int MPI_Send( void* buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm );
int MPI_Bcast( void* buf, int count, MPI_Datatype datatype, int root,
MPI_Comm comm );
int MPI_Cart_create(MPI_Comm comm_old, int ndims, const int dims[],
const int periods[], int reorder, MPI_Comm* comm_cart);
int MPI_Comm_free( MPI_Comm* comm);
int MPI_Cart_coords( MPI_Comm comm, int rank, int maxdims, int* coords);
int MPI_Cart_shift( MPI_Comm comm, int dir, int disp, int* rank_source,
int* rank_dest );
int MPI_Sendrecv_replace( void* buf, int count, MPI_Datatype datatype,
int dest, int sendtag, int source, int recvtag, MPI_Comm comm,
MPI_Status* status );
#endif
#ifdef __cplusplus
}
#endif
#else
#ifndef __free
#define __free free
#endif
int coprthr_mpiexec(
int dd, unsigned int nthr,
coprthr_sym_t thrfunc, void* parg, size_t argsz,
int flag
)
{
coprthr_event_t ev;
coprthr_mem_t argmem = coprthr_dmalloc(dd,argsz,0);
ev = coprthr_dwrite(dd,argmem,0,parg,argsz,COPRTHR_E_NOW);
__coprthr_free_event(ev);
free(ev);
coprthr_attr_t attr;
coprthr_td_t td;
void* status;
coprthr_attr_init( &attr );
coprthr_attr_setdetachstate(&attr,COPRTHR_CREATE_JOINABLE);
coprthr_attr_setdevice(&attr,dd);
coprthr_ncreate( nthr, &td, &attr, thrfunc, (void*)&argmem );
/* TODO: td seems to leak too */
coprthr_attr_destroy( &attr);
coprthr_join(td,&status);
ev = coprthr_dread(dd,argmem,0,parg,argsz,COPRTHR_E_NOW);
__coprthr_free_event(ev);
free(ev);
coprthr_dfree(dd,argmem);
}
#endif
#endif