Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get trace category from surf_action instead of smx_action when tracing categorized...
[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_alloc ()
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_release (void)
63 {
64   TRACE_surf_release ();
65   if (IS_TRACING_SMPI){
66     TRACE_end();
67   }
68 }
69
70 void TRACE_smpi_init (int rank)
71 {
72   if (!IS_TRACING_SMPI) return;
73
74   char str[100];
75   TRACE_smpi_container (rank, str, 100);
76   pajeCreateContainer (SIMIX_get_clock(), str, "MPI_PROCESS",
77       SIMIX_host_get_name(SIMIX_host_self()), str);
78 }
79
80 void TRACE_smpi_finalize (int rank)
81 {
82   if (!IS_TRACING_SMPI) return;
83
84   char str[100];
85   pajeDestroyContainer (SIMIX_get_clock(), "MPI_PROCESS",
86       TRACE_smpi_container (rank, str, 100));
87 }
88
89 void TRACE_smpi_collective_in (int rank, int root, const char *operation)
90 {
91   if (!IS_TRACING_SMPI) return;
92
93   char str[100];
94   pajePushState (SIMIX_get_clock(), "MPI_STATE",
95       TRACE_smpi_container (rank, str, 100), operation);
96 }
97
98 void TRACE_smpi_collective_out (int rank, int root, const char *operation)
99 {
100   if (!IS_TRACING_SMPI) return;
101
102   char str[100];
103   pajePopState (SIMIX_get_clock(), "MPI_STATE",
104       TRACE_smpi_container (rank, str, 100));
105 }
106
107 void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation)
108 {
109   if (!IS_TRACING_SMPI) return;
110
111   char str[100];
112   pajePushState (SIMIX_get_clock(), "MPI_STATE",
113       TRACE_smpi_container (rank, str, 100), operation);
114 }
115
116 void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation)
117 {
118   if (!IS_TRACING_SMPI) return;
119
120   char str[100];
121   pajePopState (SIMIX_get_clock(), "MPI_STATE",
122       TRACE_smpi_container (rank, str, 100));
123 }
124
125 void TRACE_smpi_send (int rank, int src, int dst)
126 {
127   if (!IS_TRACING_SMPI) return;
128
129   char key[100], str[100];
130   TRACE_smpi_put_key (src, dst, key, 100);
131   pajeStartLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
132       TRACE_smpi_container (src, str, 100), key);
133 }
134
135 void TRACE_smpi_recv (int rank, int src, int dst)
136 {
137   if (!IS_TRACING_SMPI) return;
138
139   char key[100], str[100];
140   TRACE_smpi_get_key (src, dst, key, 100);
141   pajeEndLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
142       TRACE_smpi_container (dst, str, 100), key);
143 }
144 #endif
145