MulticoreBSP for C  Version 1.1
mcinternal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 by Albert-Jan N. Yzelman
3  *
4  * This file is part of MulticoreBSP in C --
5  * a port of the original Java-based MulticoreBSP.
6  *
7  * MulticoreBSP for C is distributed as part of the original
8  * MulticoreBSP and is free software: you can redistribute
9  * it and/or modify it under the terms of the GNU Lesser
10  * General Public License as published by the Free Software
11  * Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  * MulticoreBSP is distributed in the hope that it will be
14  * useful, but WITHOUT ANY WARRANTY; without even the
15  * implied warranty of MERCHANTABILITY or FITNESS FOR A
16  * PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General
20  * Public License along with MulticoreBSP. If not, see
21  * <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef _H_MCINTERNAL
25 #define _H_MCINTERNAL
26 
27 #include "mcbsp-internal.h"
28 #include "mcutil.h"
29 
30 #include <stdio.h>
31 #include <errno.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <pthread.h>
35 #include <stdbool.h>
36 
37 #ifdef __MACH__
38  #include <mach/mach.h>
39  #include <mach/clock.h>
40  #include <mach/mach_error.h>
41 #endif
42 
43 #ifdef _WIN32
44  #include <windows.h>
45 #endif
46 
51 
53  void (*spmd)(void);
54 
58  void *bsp_program;
59 
61  int argc;
62 
64  char **argv;
65 
67  pthread_t *threads;
68 
71 
73  volatile bool abort;
74 
76  bool ended;
77 
83 
89 
91  pthread_mutex_t mutex;
92 
93 #ifdef MCBSP_USE_SPINLOCK
94 
95  unsigned char * condition;
96 
98  unsigned char * mid_condition;
99 #else
100 
101  pthread_cond_t condition;
102 
104  pthread_cond_t mid_condition;
105 #endif
106 
109 
112 
115 
117  size_t tagSize;
118 
119 };
120 
125 
128 
131 
132 #ifdef __MACH__
133 
134  clock_serv_t clock;
135 
140  mach_timespec_t start;
141 #elif _WIN32
142 
146  LARGE_INTEGER start;
147 
152  LARGE_INTEGER frequency;
153 #else
154 
155  struct timespec start;
156 #endif
157 
160 
165  unsigned long int localC;
166 
172 
178 
184 
190 
198 
203  size_t newTagSize;
204 
207 
210 
215 
216 };
217 
223 
225  void * source;
226 
228  void * destination;
229 
231  size_t length;
232 
233 };
234 
244 
246  void * destination;
247 
249  size_t length;
250 
251 };
252 
258 
260  const void * payload;
261 
263  const void * tag;
264 
266  size_t payload_size;
267 
268 };
269 
272 
274  void * address;
275 
278 
279 };
280 
282 extern pthread_key_t mcbsp_internal_init_data;
283 
285 extern pthread_key_t mcbsp_internal_thread_data;
286 
290 extern pthread_key_t mcbsp_internal_init_data;
291 
294 
299 extern pthread_mutex_t mcbsp_internal_key_mutex;
300 
306 void bsp_init_internal( struct mcbsp_init_data * const initialisationData );
307 
318 
326 
331 
336 void* mcbsp_internal_spmd();
337 
343 
344 #ifdef MCBSP_USE_SPINLOCK
345 
354 void mcbsp_internal_sync( struct mcbsp_init_data * const init, const size_t bsp_id );
355 #else
356 
363 void mcbsp_internal_sync( struct mcbsp_init_data * const init );
364 #endif
365 
366 #ifdef MCBSP_USE_SPINLOCK
367 
383 void mcbsp_internal_syncWithCondition( struct mcbsp_init_data * const init,
384  volatile unsigned char * const condition, const size_t bsp_id );
385 #else
386 
399 void mcbsp_internal_syncWithCondition( struct mcbsp_init_data * const init,
400  pthread_cond_t * const condition );
401 #endif
402 
409 
415 
417 extern int main( int argc, char** argv );
418 
419 #endif
420