MulticoreBSP for C  Version 2.0.4
mcbsp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012
3  *
4  * File created 2012 by A. N. Yzelman by refactoring a much
5  * older header file (2007-2009).
6  *
7  * This file is part of MulticoreBSP in C --
8  * a port of the original Java-based MulticoreBSP.
9  *
10  * MulticoreBSP for C is distributed as part of the original
11  * MulticoreBSP and is free software: you can redistribute
12  * it and/or modify it under the terms of the GNU Lesser
13  * General Public License as published by the Free Software
14  * Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  * MulticoreBSP is distributed in the hope that it will be
17  * useful, but WITHOUT ANY WARRANTY; without even the
18  * implied warranty of MERCHANTABILITY or FITNESS FOR A
19  * PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General
23  * Public License along with MulticoreBSP. If not, see
24  * <http://www.gnu.org/licenses/>.
25  */
26 
27 #ifndef _H_MCINTERNAL
28 #define _H_MCINTERNAL
29 
30 //this include has to come first,
31 //as it defines compilation modes
32 #include "mcbsp-internal-macros.h"
33 
34 //public MulticoreBSP includes:
35 #include "bsp.h"
36 #include "mcbsp-affinity.h"
37 #include "mcbsp-profiling.h"
38 #include "mcbsp-resiliency.h"
39 
40 //hidden includes (from library user's perspective):
41 
42 //cross-platform includes:
43 #ifdef __MACH__
44  #include <mach/mach.h>
45  #include <mach/clock.h>
46  #include <mach/mach_error.h>
47  #include <mach/thread_policy.h>
48 #endif
49 
50 #ifdef _WIN32
51  #include <windows.h>
52 #endif
53 
54 #ifdef MCBSP_WITH_DMTCP
55  #include <dmtcp.h>
56 #endif
57 
58 //common includes:
59 #include <time.h>
60 #include <stdio.h>
61 #include <errno.h>
62 #include <sched.h>
63 #include <stdlib.h>
64 #include <unistd.h>
65 #include <assert.h>
66 #include <signal.h>
67 #include <pthread.h>
68 #include <stdbool.h>
69 
70 #include "mcutil.h"
71 
72 #define MCBSP_SUPERSTEP_STATS_NAME_MAX 255
73 
74 
76 extern int main( int argc, char **argv );
77 
80 
86 
88  size_t put;
89 
91  size_t get;
92 
94  size_t hpput;
95 
97  size_t hpget;
98 
100  size_t send;
101 
103  size_t hpsend;
104 
106  size_t direct_get;
107 
109  size_t move;
110 
112  size_t hpmove;
113 
121  size_t bookkeeping;
122 
133 
138 
143 
148  size_t bytes_sent;
149 
155 
161 
167 
169  double buffering;
170 
172  double computation;
173 
176 
177 };
178 
199 
201  size_t P;
202 
208 
214 
216  size_t tagSize;
217 
227  size_t top_pid;
228 
230  size_t cp_f;
231 
233  size_t safe_cp_f;
234 
244 
247 
249  pthread_t *threads;
250 
253 
260  unsigned char * sl_condition;
261 
268  unsigned char * sl_mid_condition;
269 
274  unsigned char * sl_end_condition;
275 
278 
280  void (*spmd)(void);
281 
286  void *bsp_program;
287 
289  char **argv;
290 
293 
295  pthread_mutex_t mutex;
296 
305  pthread_cond_t condition;
306 
315  pthread_cond_t mid_condition;
316 
321  pthread_cond_t end_condition;
322 
324  int argc;
325 
327  volatile bool abort;
328 
330  bool ended;
331 
333  bool no_cp;
334 
339  bool safe_cp;
340 
341 };
342 
349 
351  size_t bsp_id;
352 
357  size_t newTagSize;
358 
363  size_t localC;
364 
370 
373 
379 
385 
393 
396 
410 
413 
416 
422 
428 
431 
437 
440 
443 
444 #ifdef __MACH__
445 
446  clock_serv_t clock;
447 
452  mach_timespec_t start;
453 #elif defined _WIN32
454 
458  LARGE_INTEGER start;
459 
464  LARGE_INTEGER frequency;
465 #else
466 
470  struct timespec start;
471 #endif
472 };
473 
479 
481  void * source;
482 
484  void * destination;
485 
487  size_t length;
488 
489 };
490 
500 
502  void * destination;
503 
505  size_t length;
506 
507 };
508 
514 
516  const void * source;
517 
519  void * destination;
520 
522  size_t length;
523 
531 };
532 
538 
540  const void * payload;
541 
543  const void * tag;
544 
546  size_t payload_size;
547 
548 };
549 
552 
554  void * address;
555 
557  size_t size;
558 
559 };
560 
562 extern pthread_key_t mcbsp_internal_init_data;
563 
565 extern pthread_key_t mcbsp_internal_thread_data;
566 
568 extern pthread_key_t mcbsp_local_machine_info;
569 
574 extern pthread_key_t mcbsp_internal_init_data;
575 
578 
584 extern pthread_mutex_t mcbsp_internal_keys_mutex;
585 
586 //include the currently active hooks for accelerator support
587 #include "bsp-active-hooks.h"
588 
594 void bsp_init_internal( struct mcbsp_init_data * const initialisationData );
595 
603 
608 
615 void* mcbsp_internal_spmd( void *p );
616 
621 void mcbsp_internal_check_aborted( void );
622 
633 void mcbsp_internal_spinlock( struct mcbsp_init_data * const init, unsigned char * const cond, const size_t bsp_id );
634 
643 void mcbsp_internal_sync( struct mcbsp_init_data * const init, pthread_cond_t *cond );
644 
651 
657 
665 struct mcbsp_thread_data * mcbsp_internal_allocate_thread_data( struct mcbsp_init_data * const init, const size_t s );
666 
677 
683 void mcbsp_internal_destroy_thread_data( struct mcbsp_thread_data * const data );
684 
694 
708 
714 void mcbsp_internal_print_profile( const struct mcbsp_init_data * const init );
715 
725 void mcbsp_internal_init_superstep_stats( struct mcbsp_superstep_stats * const stats, const size_t superstep );
726 
735 double mcbsp_internal_time( struct mcbsp_thread_data * const data );
736 
737 #endif
738 
size_t metabytes_received
Stores how many bytes of bytes_received were spent on meta-data, instead of actual payloads...
Definition: mcbsp.h:166
struct mcbsp_util_stack bsmp
The BSMP incoming message queue.
Definition: mcbsp.h:412
bool safe_cp
Whether hardware failures were detected, or were detected to be imminent.
Definition: mcbsp.h:339
size_t move
Stores the recorded number of calls to bsp_move.
Definition: mcbsp.h:109
size_t hpput
Stores the recorded number of calls to bsp_hpput.
Definition: mcbsp.h:94
void * destination
Destination.
Definition: mcbsp.h:519
size_t direct_get
Stores the recorded number of calls to bsp_direct_get.
Definition: mcbsp.h:106
void * source
Source.
Definition: mcbsp.h:481
size_t length
Length.
Definition: mcbsp.h:522
struct mcbsp_init_data * init
Initialisation data.
Definition: mcbsp.h:372
void * bsp_program
In case of a call from the C++ wrapper, pointer to the user-defined BSP_program.
Definition: mcbsp.h:286
unsigned char * sl_condition
Condition used for critical sections.
Definition: mcbsp.h:260
struct mcbsp_thread_data * mcbsp_internal_initialize_thread_data(struct mcbsp_thread_data *const data)
Finishes initialisation of a mcbsp_thread_data struct.
pthread_cond_t end_condition
Condition used for critical sections.
Definition: mcbsp.h:321
struct mcbsp_thread_data * mcbsp_internal_allocate_thread_data(struct mcbsp_init_data *const init, const size_t s)
Allcates and initialises the `plain old data&#39; parts of the mcbsp_thread_data struct, using the supplied parameters.
struct timespec start
Stores the start-time of this thread.
Definition: mcbsp.h:470
struct mcbsp_util_stack localsToRemove
Keeps track which globals will be removed before the next superstep arrives.
Definition: mcbsp.h:427
Struct used to store tracked of superstep statistics.
Definition: mcbsp.h:79
A map from pointers to unsigned long ints.
Definition: mcutil.h:178
size_t bytes_received
Stores the number of bytes received during communication.
Definition: mcbsp.h:154
size_t bsp_id
Thread-local BSP id.
Definition: mcbsp.h:351
void(* spmd)(void)
User-definied SPMD entry-point.
Definition: mcbsp.h:280
Structure representing the machine hardware information.
Definition: mcutil.h:69
void mcbsp_internal_print_profile(const struct mcbsp_init_data *const init)
Prints any collected profiling statistics to stdout.
size_t P
Number of processors involved in this run.
Definition: mcbsp.h:201
const void * payload
Payload source.
Definition: mcbsp.h:540
Self-growing stack.
Definition: mcutil.h:206
struct mcbsp_util_address_map local2global
Local address to global variable map.
Definition: mcbsp.h:395
size_t length
Length.
Definition: mcbsp.h:487
size_t current_superstep
Current superstep of the SPMD program.
Definition: mcbsp.h:246
volatile bool abort
Whether the BSP program should be aborted.
Definition: mcbsp.h:327
double mcbsp_internal_time(struct mcbsp_thread_data *const data)
Gets the time relative to the SPMD start section.
struct mcbsp_util_stack hpdrma_queue
The communication queue for hpget and hpput requests.
Definition: mcbsp.h:409
A DRMA communication request for hpput and hpget requests.
Definition: mcbsp.h:513
unsigned char * sl_end_condition
Condition used for critical section.
Definition: mcbsp.h:274
pthread_mutex_t mutex
Mutex used for critical sections (such as synchronisation).
Definition: mcbsp.h:295
int mcbsp_internal_call_checkpoint(void)
Does the checkpointing from within a critical section.
struct mcbsp_superstep_stats superstep_stats
Stores statistics on the current superstep.
Definition: mcbsp.h:442
bool source_is_remote
Whether source is the remote PID.
Definition: mcbsp.h:530
double computation
Stores the time taken in the computation phase.
Definition: mcbsp.h:172
double buffering
Stores the time taken in buffering during computation phases.
Definition: mcbsp.h:169
size_t metabytes_sent
Stores how many bytes of bytes_sent were spent on meta-data, instead of actual payloads.
Definition: mcbsp.h:160
pthread_key_t mcbsp_internal_init_data
Per-initialising thread initialisation data.
Definition: mcbsp.h:574
void mcbsp_internal_sync(struct mcbsp_init_data *const init, pthread_cond_t *cond)
Alias for mcbsp_internal_syncWithCondition using the standard init.condition.
A generic BSP communication message.
Definition: mcbsp.h:499
size_t skipped_checkpoints
Current number of skipped checkpoints.
Definition: mcbsp.h:243
struct mcbsp_util_stack localsToPush
The push request queue.
Definition: mcbsp.h:430
struct mcbsp_util_stack * request_queues
The communication queues used for bsp_get requests.
Definition: mcbsp.h:378
struct mcbsp_thread_data ** threadData
Pointers to all thread-local data, as needed for communication.
Definition: mcbsp.h:252
#define MCBSP_SUPERSTEP_STATS_NAME_MAX
Definition: mcbsp.h:72
size_t bytes_buffered
Stores the number of bytes locally buffered.
Definition: mcbsp.h:137
void * destination
Destination.
Definition: mcbsp.h:484
char name[MCBSP_SUPERSTEP_STATS_NAME_MAX]
Stores a descriptive name for the superstep this is storing statistics of.
Definition: mcbsp.h:85
pthread_mutex_t mcbsp_internal_keys_mutex
Contorls thread-safe singleton access to mcbsp_internal_init_data.
void bsp_init_internal(struct mcbsp_init_data *const initialisationData)
Performs a BSP intialisation using the init struct supplied.
void * address
The local address to push.
Definition: mcbsp.h:554
bool no_cp
Whether checkpointing has been explicitly disallowed.
Definition: mcbsp.h:333
size_t hpmove
Stores the recorded number of calls to bsp_hpmove.
Definition: mcbsp.h:112
size_t send
Stores the recorded number of calls to bsp_send.
Definition: mcbsp.h:100
double superstep_start_time
The value of bsp_time at the start of the current computation phase.
Definition: mcbsp.h:369
struct mcbsp_util_stack profile
Where to store any profiling statistics.
Definition: mcbsp.h:415
size_t direct_get_bytes
Stores the number of bytes transferred using bsp_direct_get.
Definition: mcbsp.h:142
void mcbsp_internal_update_checkpointStats(struct mcbsp_init_data *const init)
On encountering a new superstep, this function takes care of bookkeeping regarding checkpointing freq...
size_t hpget
Stores the recorded number of calls to bsp_hpget.
Definition: mcbsp.h:97
pthread_cond_t condition
Condition used for critical sections.
Definition: mcbsp.h:305
const void * tag
Tag source.
Definition: mcbsp.h:543
size_t hpsend
Stores the recorded number of calls to bsp_hpsend.
Definition: mcbsp.h:103
size_t payload_size
Payload length.
Definition: mcbsp.h:546
Thread-local data.
Definition: mcbsp.h:348
size_t tagSize
Currently active tag size.
Definition: mcbsp.h:216
struct mcbsp_util_machine_partition machine_partition
Stores the machine part allocated to this thread.
Definition: mcbsp.h:439
int argc
Passed argc from bsp_init.
Definition: mcbsp.h:324
struct mcbsp_util_stack globalsToPush
Caches the mapSearch results for use with bsp_push_reg requests.
Definition: mcbsp.h:436
size_t sync_exit_counter
Barrier counter for this BSP program.
Definition: mcbsp.h:213
struct mcbsp_util_machine_info * mcbsp_internal_getMachineInfo(void)
Gets the machine info currently active for this MulticoreBSP session.
Struct corresponding to a single push request.
Definition: mcbsp.h:551
A table of local address locations per SPMD variable.
Definition: mcutil.h:241
size_t size
The memory range to register.
Definition: mcbsp.h:557
void mcbsp_internal_init_superstep_stats(struct mcbsp_superstep_stats *const stats, const size_t superstep)
(Re-)initialises the superstep stats structure.
size_t top_pid
ID of the top-level run, if available.
Definition: mcbsp.h:227
double communication
Stores the time taken in the communication phase.
Definition: mcbsp.h:175
struct mcbsp_thread_data * prev_data
Stores any previous thread-local data.
Definition: mcbsp.h:277
struct mcbsp_thread_data * mcbsp_internal_prefunction(void)
Common part executed by all BSP primitives when in SPMD part.
pthread_cond_t mid_condition
Condition used for critical sections.
Definition: mcbsp.h:315
struct mcbsp_util_stack * hpsend_queues
The communication queues used for bsp_hpsend requests.
Definition: mcbsp.h:392
pthread_key_t mcbsp_internal_thread_data
Per-thread data.
pthread_t * threads
Threads corresponding to this BSP program.
Definition: mcbsp.h:249
void mcbsp_internal_spinlock(struct mcbsp_init_data *const init, unsigned char *const cond, const size_t bsp_id)
Alias for mcbsp_internal_syncWithCondition using the standard init.condition.
bool ended
Whether the BSP program has ended.
Definition: mcbsp.h:330
void * destination
Destination.
Definition: mcbsp.h:502
struct mcbsp_util_address_table global2local
Address table used for inter-thread communication.
Definition: mcbsp.h:292
size_t safe_cp_f
Currently active safe checkpointing frequency.
Definition: mcbsp.h:233
void mcbsp_internal_check_aborted(void)
Checks if a abort has been requested, and if so, exits the current thread.
struct mcbsp_util_stack removedGlobals
Keeps track of which global variables are removed (as per bsp_pop_reg).
Definition: mcbsp.h:421
int main(int argc, char **argv)
To support direct SPMD mode, created threads may call main().
size_t localC
Counts the maximum number of registered variables at any one time.
Definition: mcbsp.h:363
size_t cp_f
Currently active checkpointing frequency.
Definition: mcbsp.h:230
pthread_key_t mcbsp_local_machine_info
Per-thread machine info.
size_t newTagSize
Stores the tag size to become active after the next synchronisation.
Definition: mcbsp.h:357
void * mcbsp_internal_spmd(void *p)
Entry-point of MulticoreBSP threads.
Structure representing a part of the current machine.
Definition: mcutil.h:53
struct mcbsp_thread_data * mcbsp_internal_const_prefunction(void)
Common part executed by all BSP primitives when in SPMD part.
size_t sync_entry_counter
Barrier counter for this BSP execution.
Definition: mcbsp.h:207
struct mcbsp_util_stack * queues
The communication queues used for all DRMA and BSMP communication.
Definition: mcbsp.h:384
void mcbsp_internal_destroy_thread_data(struct mcbsp_thread_data *const data)
Deallocates a fully initialised mcbsp_thread_data struct.
A high-performance (non-buffering) BSMP message request.
Definition: mcbsp.h:537
char ** argv
Passed argv from bsp_init.
Definition: mcbsp.h:289
size_t put
Stores the recorded number of calls to bsp_put.
Definition: mcbsp.h:88
const void * source
Source.
Definition: mcbsp.h:516
void MCBSP_FUNCTION_PREFIX() init(void(*spmd)(void), int argc, char **argv)
void mcbsp_internal_check_keys_allocated(void)
Singleton thread-safe allocator for mcbsp_internal_init_data.
bool mcbsp_internal_keys_allocated
Whether mcbsp_internal_init_data is initialised.
unsigned char * sl_mid_condition
Condition used for critical sections.
Definition: mcbsp.h:268
size_t non_communicating
Stores the recorded number of calls to non-communication primitives, namely -bsp_pid -bsp_nprocs -bsp...
Definition: mcbsp.h:132
Initialisation struct.
Definition: mcbsp.h:198
size_t bytes_sent
Stores the number of bytes sent out during communication.
Definition: mcbsp.h:148
A DRMA communication request for `get&#39;-requests.
Definition: mcbsp.h:478
size_t length
Length.
Definition: mcbsp.h:505
size_t bookkeeping
Stores the recorded number of calls to inter-process bookkeeping primitives, namely -bsp_push_reg -bs...
Definition: mcbsp.h:121