Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix on smpi tracing: check if tracing is disabled
[simgrid.git] / src / instr / smpi_instr.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "instr/private.h"
8
9 #ifdef HAVE_TRACING
10
11 static xbt_dict_t keys;
12
13 static char *_TRACE_smpi_container (int rank, char *container, int n)
14 {
15   snprintf (container, n, "rank-%d", rank);
16   return container;
17 }
18
19 static char *_TRACE_smpi_put_key (int src, int dst, char *key, int n)
20 {
21   //get the dynar for src#dst
22   char aux[100];
23   snprintf (aux, 100, "%d#%d", src, dst);
24   xbt_dynar_t d = xbt_dict_get_or_null (keys, aux);
25   if (d == NULL){
26     d = xbt_dynar_new (sizeof(char*), xbt_free);
27     xbt_dict_set (keys, aux, d, xbt_free);
28   }
29   //generate the key
30   static long long counter = 0;
31   snprintf (key, n, "%d%d%lld", src, dst, counter++);
32
33   xbt_dynar_insert_at (d, 0, xbt_strdup (key));
34   return key;
35 }
36
37 static char *_TRACE_smpi_get_key (int src, int dst, char *key, int n)
38 {
39   char aux[100];
40   snprintf (aux, 100, "%d#%d", src, dst);
41   xbt_dynar_t d = xbt_dict_get_or_null (keys, aux);
42
43   int length = xbt_dynar_length (d);
44   char stored_key[n];
45   xbt_dynar_remove_at (d, length-1, stored_key);
46   strncpy (key, stored_key, n);
47   return key;
48 }
49
50 void __TRACE_smpi_init ()
51 {
52   keys = xbt_dict_new();
53 }
54
55 void TRACE_smpi_start (void)
56 {
57   if (IS_TRACING_SMPI){
58     TRACE_start ();
59   }
60 }
61
62 void TRACE_smpi_end (void)
63 {
64   if (IS_TRACING_SMPI){
65     TRACE_end();
66   }
67 }
68
69 void TRACE_smpi_init (int rank)
70 {
71   if (!IS_TRACING_SMPI) return;
72
73   char str[100];
74   _TRACE_smpi_container (rank, str, 100);
75   pajeCreateContainer (SIMIX_get_clock(), str, "MPI_PROCESS",
76       SIMIX_host_get_name(SIMIX_host_self()), str);
77 }
78
79 void TRACE_smpi_finalize (int rank)
80 {
81   if (!IS_TRACING_SMPI) return;
82
83   char str[100];
84   pajeDestroyContainer (SIMIX_get_clock(), "MPI_PROCESS",
85       _TRACE_smpi_container (rank, str, 100));
86 }
87
88 void TRACE_smpi_collective_in (int rank, int root, const char *operation)
89 {
90   if (!IS_TRACING_SMPI) return;
91
92   char str[100];
93   pajePushState (SIMIX_get_clock(), "MPI_STATE",
94       _TRACE_smpi_container (rank, str, 100), operation);
95 }
96
97 void TRACE_smpi_collective_out (int rank, int root, const char *operation)
98 {
99   if (!IS_TRACING_SMPI) return;
100
101   char str[100];
102   pajePopState (SIMIX_get_clock(), "MPI_STATE",
103       _TRACE_smpi_container (rank, str, 100));
104 }
105
106 void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation)
107 {
108   if (!IS_TRACING_SMPI) return;
109
110   char str[100];
111   pajePushState (SIMIX_get_clock(), "MPI_STATE",
112       _TRACE_smpi_container (rank, str, 100), operation);
113 }
114
115 void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation)
116 {
117   if (!IS_TRACING_SMPI) return;
118
119   char str[100];
120   pajePopState (SIMIX_get_clock(), "MPI_STATE",
121       _TRACE_smpi_container (rank, str, 100));
122 }
123
124 void TRACE_smpi_send (int rank, int src, int dst)
125 {
126   if (!IS_TRACING_SMPI) return;
127
128   char key[100], str[100];
129   _TRACE_smpi_put_key (src, dst, key, 100);
130   pajeStartLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
131       _TRACE_smpi_container (src, str, 100), key);
132 }
133
134 void TRACE_smpi_recv (int rank, int src, int dst)
135 {
136   if (!IS_TRACING_SMPI) return;
137
138   char key[100], str[100];
139   _TRACE_smpi_get_key (src, dst, key, 100);
140   pajeEndLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
141       _TRACE_smpi_container (dst, str, 100), key);
142 }
143 #endif
144