Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Sync_Time_MPI.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #define _GNU_SOURCE
20 #include <dlfcn.h>
21 #include <unistd.h>
22 #include <mpi.h>
23 #include <stdio.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include "Timer.h"
28 
29 
30 
31 #ifndef SYNC_TIME
32 #define SYNC_TIME
33 
43 #define MAX_LOOP_TRY 20
44 
48 #define SYNC_TAG 1234
49 
53 #define MAX_AVG 10
54 
55 
63  int comm_size;
64  long long int offset;
65 };
66 
67 
68 
69 
73 void sync_mpi();
74 
75 
76 
93 void compute_sync_tree( struct sync_tree_conf *conf,
94  void (*action)(struct sync_tree_conf *next_conf, void *arg),
95  void (*per_child_act)(struct sync_tree_conf *conf, void *arg ),
96  void (*post_action)(struct sync_tree_conf *next_conf, void *arg),
97  void *arg
98  );
99 
100 
101 
115 void bootstrap_sync_tree( void (*action)(struct sync_tree_conf *next_conf, void *arg),
116  void (*per_child_act)(struct sync_tree_conf *conf , void *arg),
117  void (*post_action)(struct sync_tree_conf *next_conf, void *arg),
118  void *arg
119  );
120 
121 //TREE ACTIONS
129 void perchild_host(struct sync_tree_conf *c, void *arg);
130 
138 void post_client(struct sync_tree_conf *c, void *arg);
139 
145 void action_set_off(struct sync_tree_conf *c, void *poffset);
146 // ~~~ DBG
147 
155 void action_val(struct sync_tree_conf *c, void *arg);
156 
157 
158 
159 //SYNC
164 void sync_server( int dest_rank );
165 
171 void sync_client(int parent, void *poffset);
172 
173 
177 extern long long int Process_Sync_Offset;
184 //UTILITIES FUNCTIONS
185 
192 static inline uint64_t abs_diff( uint64_t a , uint64_t b )
193 {
194  if( a < b )
195  return b - a;
196  else
197  return a - b;
198 }
199 
205 static inline uint32_t nearest_pow (uint32_t num)
206 {
207  uint32_t n = num > 0 ? num - 1 : 0;
208 
209  n |= n >> 1;
210  n |= n >> 2;
211  n |= n >> 4;
212  n |= n >> 8;
213  n |= n >> 16;
214  n++;
215 
216  return n;
217 }
218 
219 
220 
226 #endif
static uint32_t nearest_pow(uint32_t num)
Computes the nearest.
void perchild_host(struct sync_tree_conf *c, void *arg)
What to be done on each node's child.
int target_node
the target node
Definition: Sync_Time_MPI.h:61
int current_pow
the current nearest power of two
Definition: Sync_Time_MPI.h:62
void sync_mpi()
Entry point to be used to perform time sync of every MPI Processes.
long long int Process_Sync_Offset
The offset of the timer.
Definition: Timer.c:22
void bootstrap_sync_tree(void(*action)(struct sync_tree_conf *next_conf, void *arg), void(*per_child_act)(struct sync_tree_conf *conf, void *arg), void(*post_action)(struct sync_tree_conf *next_conf, void *arg), void *arg)
This is a bootstrapping function for calling compute_sync_tree();.
Definition: Sync_Time_MPI.c:93
void action_set_off(struct sync_tree_conf *c, void *poffset)
Copies offset of c to current process timer offset (poffset)
static uint64_t abs_diff(uint64_t a, uint64_t b)
Computes an absolute difference.
This structure describes a tree node for time synchronization.
Definition: Sync_Time_MPI.h:59
int source_node
the source node
Definition: Sync_Time_MPI.h:60
void sync_client(int parent, void *poffset)
The client function for synchronizing time (computes offset between server and client) ...
long long int offset
the time offset
Definition: Sync_Time_MPI.h:64
void post_client(struct sync_tree_conf *c, void *arg)
What to be done on the client side.
void sync_server(int dest_rank)
Server function for synchronizing time.
void action_val(struct sync_tree_conf *c, void *arg)
For debugging only.
int comm_size
the total number of ranks
Definition: Sync_Time_MPI.h:63
void compute_sync_tree(struct sync_tree_conf *conf, void(*action)(struct sync_tree_conf *next_conf, void *arg), void(*per_child_act)(struct sync_tree_conf *conf, void *arg), void(*post_action)(struct sync_tree_conf *next_conf, void *arg), void *arg)
This function does the actual work prepared by bootstrap_sync_tree().
Definition: Sync_Time_MPI.c:22