Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
main.c
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 #include "MPI_Events.h"
20 #include <stdio.h>
21 #include <mpi.h>
22 #include <pthread.h>
23 #include "VMPI.h"
24 #include "Timer.h"
25 #include "Trace_Comm.h"
26 #include "Sync_Time_MPI.h"
27 #include "Stream_MGR.h"
28 #include "Event_Pack.h"
29 #include "Posix_Wrapp.h"
30 #include "MALP_Config.h"
31 #include "config.h"
32 #include "Posix_Profile.h"
33 
34 
35 #include "Debug.h"
36 
37 #include <execinfo.h>
38 #include <signal.h>
39 #include <stdlib.h>
40 
41 
42 #include <signal.h>
43 #include <execinfo.h>
44 
45 
46 
47 void Config_Setup(int rank)
48 {
49  if( !rank )
50  {
51  char * conf_path = getenv("MALP_CONF");
52 
53  if( !conf_path )
54  {
55  TA_Conf_load("./malp_an.conf");
56  }
57  else
58  {
59  TA_Conf_load(conf_path);
60  }
61 
62  /* We now overrride defaults from ENV */
64  }
65 
67 }
68 
69 
70 
71 void Instrumentation_Constructor() __attribute__ ((constructor));
72 
74 {
77  TEST_LOAD_SYMBOL(sleep);
78  Timer_Init_scale( REAL(sleep) );
79  Wrapp_enable();
80 }
81 
82 
83 static int is_an_mpi_program = 0;
84 
85 void Instrumentation_Destructor() __attribute__ ((destructor));
86 
88 {
89  Wrapp_disable();
91  {
93  }
94 }
95 
96 
97 
98 
99 
100 int MPI_Init(int * argc, char *** argv)
101 {
102  int d;
103  return MPI_Init_thread(argc , argv ,MPI_THREAD_SINGLE ,&d);
104 }
105 
106 
107 static const char * MALP_VERSION = "2.1";
108 
109 #if MPMD_SUPPORTED==0
110 //In this case we are linked with the analyzer
111 extern int analyzer_main( int argc, char **argv );
112 #endif
113 
114 
115 int MPI_Init_thread(int *argc ,char ***argv ,int required ,int * provided)
116 {
117  int ret;
118 
119  is_an_mpi_program = 1;
120 
122  if( (ret = PMPI_Init_thread(argc, argv, required, provided)) != MPI_SUCCESS )
123  return ret;
125 
126 #if MPMD_SUPPORTED==0
128 
129  /* Rebuild ARGV for fortran programs */
130  int new_argc = 1;
131 
132  char *prog_name = NULL;
133 
134  if( argv && *argv )
135  {
136  prog_name = (*argv)[0];
137  }
138  else
139  {
140  /* If no name give one =) */
141  prog_name = "Program";
142  }
143 
144  char ** new_argv = malloc( 2 * sizeof( char * ) );
145 
146  if( ! new_argv )
147  {
148  abort();
149  }
150 
151  new_argv[0] = strdup( prog_name );
152  new_argv[1] = NULL;
153 
154 
155  VMPI_Init(&new_argc, &new_argv);
156 #else
157  VMPI_Init(argc, argv);
158 #endif
159 
160  /* Init trace communicator */
161  Trace_Comm_init();
162  /* Sync Timestamps */
163  sync_mpi();
164 
165 
166  int rank = 0;
167 
169  PMPI_Comm_rank(VMPI_Get_partition_comm(), &rank);
171 
172  Config_Setup(rank);
173 
175  VMPI_Partition_desc *current_dest = VMPI_Get_desc();
176 
177  int displays_banner = 0;
178 
179  if(!strcmp(desc->name, "Analyzer"))
180  {
181  displays_banner = 1;
182  }
183 
184 
185  if( (rank == current_dest->root_id)
186  && (VMPI_Get_partition_id() == displays_banner)
188  {
189  fprintf(stderr,"\033[1;31m=====================================================\033[0m\n");
190  fprintf(stderr,"\033[1;31m# # ######## # #######\033[0m\n");
191  fprintf(stderr,"\033[1;31m# # # # # # # # #\033[0m\n");
192  fprintf(stderr,"\033[1;31m# # # # # # # #\033[0m\n");
193  fprintf(stderr,"\033[1;31m# # ######## # #######\033[0m\n");
194  fprintf(stderr,"\033[1;31m# # # # # #\033[0m\n");
195  fprintf(stderr,"\033[1;31m# # # # # #\033[0m\n");
196  fprintf(stderr,"\033[1;31m# # # # ####### #\033[0m\n");
197  fprintf(stderr,"\033[1;31m=============================================== \033[36m%s\033[0m \033[1;31m=\033[0m\n", MALP_VERSION);
198  }
199 
200  /* Initialize event stream */
202 
203  /* Initialize Stream Manager */
205 
206  /* Fill in root infos */
207  struct Stream_Infos *sd = Stream_MGR_new_stream( NULL, MALP_PROCESS );
208 
209  if( !sd )
210  {
211  printf("Failed to initialize stream infos\n");
212  PMPI_Abort(VMPI_Get_partition_comm(), 1);
213  }
214 
215  Stream_infos_set(sd);
216 
217  return ret;
218 }
219 
220 
222 {
224  return;
225 
226  /* Reduce POSIX profile */
228  int rank = 0;
229 
231  PMPI_Comm_rank(VMPI_Get_partition_comm(), &rank);
233 
234  if( !rank )
236 }
237 
238 
240 {
241  int ret;
242 
243  /* Disable Event notification */
244  Wrapp_disable();
245 
246  /* Render POSIX profile (if needed ) */
248 
249  /* Signal end */
251 
252  /* Release Stream Manager */
254 
255  /* Release event stream */
257 
258  /* Release trace communicator */
260 
262 
264 
265  /* Release VMPI */
266  VMPI_Release();
267 
268  ret = PMPI_Finalize();
269 
270  return ret;
271 }
static int VMPI_Set_trace_trampoline(char *trampoline_partition, int(*vmpi_trampoline)(int argc, char **argv))
Definition: VMPI.h:196
static int TA_Conf_get_key_bool(TA_Conf_key_t key)
Get a configuration parameter value of type bool.
Definition: MALP_Config.h:233
char name[200]
Name of the partition (could be NONE)
Definition: VMPI.h:105
void POSIX_profile_render()
int VMPI_Release()
Releases VMPI.
Definition: VMPI.c:840
#define REAL(a)
Definition: Posix_Wrapp.h:81
void Config_Setup(int rank)
Definition: main.c:47
void sync_mpi()
Entry point to be used to perform time sync of every MPI Processes.
void Timer_Init_scale(unsigned int(*real_usleep)(unsigned int))
Timer_Init_scale.
Definition: Timer.c:37
static MPI_Comm VMPI_Get_partition_comm()
Returns current partition's communicator.
Definition: VMPI.h:175
void Render_POSIX_profile()
Definition: main.c:221
void POSIX_profile_reduce()
Definition: Posix_Profile.c:67
void Event_Packer_release()
Releases the event packer.
Definition: Event_Pack.c:74
static void Stream_Infos_leave_mpi()
Indicates to the current Stream_Infos (if any) that we are leaving a MPI call.
Definition: Stream_MGR.h:166
struct Stream_Infos * Stream_MGR_new_stream(struct Stream_Descriptor *parent, Stream_type type)
Adds a stream into the current stream manager.
Definition: Stream_MGR.c:89
int analyzer_main(int argc, char **argv)
void Instrumentation_Destructor()
Definition: main.c:87
void TA_Conf_load(char *source)
Load and use a file to set the Analyzer configuration.
Definition: MALP_Config.c:285
Structure describing a stream.
Definition: Stream_MGR.h:101
void Instrumentation_Constructor()
Definition: main.c:73
Structure holding partitions descriptions.
Definition: VMPI.h:100
static const char * MALP_VERSION
Definition: main.c:107
int MPI_Init_thread(int *argc, char ***argv, int required, int *provided)
Definition: main.c:115
static int is_an_mpi_program
Definition: main.c:83
void Stream_Manager_init()
Initialises the manager for current MPI process.
Definition: Stream_MGR.c:56
void TA_Conf_init_default()
Initialisation of the Trace_Collector with default options.
Definition: MALP_Config.c:152
void Wrapp_enable()
Definition: Posix_Wrapp.c:44
#define TEST_LOAD_SYMBOL(a)
Definition: Posix_Wrapp.h:83
int root_id
Identifier of the root of the partition.
Definition: VMPI.h:103
void Stream_MGR_end_stream()
Signals end of stream.
Definition: Stream_MGR.c:138
void TA_Conf_init_from_env()
Initialisation of config from environment.
Definition: MALP_Config.c:131
static VMPI_Partition_desc * VMPI_Get_desc_by_id(int id)
Find a descriptions by its ID.
Definition: VMPI.h:247
#define TA_Conf_dispatch()
Start broadcasting for the analyzer.
Definition: MALP_Config.h:297
Source is a process.
static void Stream_Infos_enter_mpi()
Indicates to the current Stream_Infos (if any) that we are enterning a MPI call.
Definition: Stream_MGR.h:155
static int VMPI_Get_partition_id()
Returns the unique ID of the current partition.
Definition: VMPI.h:142
void Trace_Comm_init()
Initializes the trace communicator.
Definition: Trace_Comm.c:30
void Event_Packer_init()
Initializes the event packer, maps current process to existing Analyser or IO_WRITE partition and ini...
Definition: Event_Pack.c:30
static VMPI_Partition_desc * VMPI_Get_desc()
Returns current partition's descriptions.
Definition: VMPI.h:153
int MPI_Init(int *argc, char ***argv)
Definition: main.c:100
void Wrapp_disable()
Definition: Posix_Wrapp.c:50
void Posix_Wrapp_init()
Definition: Posix_Wrapp.c:69
int MPI_Finalize()
Definition: main.c:239
int VMPI_Init(int *argc, char ***argv)
Initializes VMPI.
Definition: VMPI.c:758
static void Stream_infos_set(struct Stream_Infos *sd)
Setter on the current Stream_Infos.
Definition: Stream_MGR.h:138
void Stream_Manager_release()
Releases the manager for current MPI process (including all streams )
Definition: Stream_MGR.c:66
void Trace_Comm_release()
Releases the trace communicator.
Definition: Trace_Comm.c:39