Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4eac5a005b9586dba1699cf0211a264d6089fe9c
[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[INSTR_DEFAULT_STR_SIZE];
23   snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%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_ref);
27     xbt_dict_set(keys, aux, d, xbt_free);
28   }
29   //generate the key
30   static unsigned long long counter = 0;
31   snprintf(key, n, "%d%d%lld", src, dst, counter++);
32
33   //push it
34   char *a = (char*)xbt_strdup(key);
35   xbt_dynar_push_as(d, char *, a);
36
37   return key;
38 }
39
40 static char *TRACE_smpi_get_key(int src, int dst, char *key, int n)
41 {
42   char aux[INSTR_DEFAULT_STR_SIZE];
43   snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d", src, dst);
44   xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
45
46   int length = xbt_dynar_length(d);
47   char *s = xbt_dynar_get_as (d, length-1, char *);
48   snprintf (key, n, "%s", s);
49   xbt_dynar_remove_at (d, length-1, NULL);
50   return key;
51 }
52
53 void TRACE_smpi_alloc()
54 {
55   keys = xbt_dict_new();
56 }
57
58 void TRACE_smpi_start(void)
59 {
60   if (IS_TRACING_SMPI) {
61     TRACE_start();
62   }
63 }
64
65 void TRACE_smpi_release(void)
66 {
67   TRACE_surf_release();
68   if (IS_TRACING_SMPI) {
69     TRACE_end();
70   }
71 }
72
73 void TRACE_smpi_init(int rank)
74 {
75   if (!IS_TRACING_SMPI)
76     return;
77
78   char str[INSTR_DEFAULT_STR_SIZE];
79   TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
80   pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
81                       SIMIX_host_get_name(SIMIX_host_self()), str);
82 }
83
84 void TRACE_smpi_finalize(int rank)
85 {
86   if (!IS_TRACING_SMPI)
87     return;
88
89   char str[INSTR_DEFAULT_STR_SIZE];
90   pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS",
91                        TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
92 }
93
94 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
95 {
96   if (!IS_TRACING_SMPI)
97     return;
98
99   char str[INSTR_DEFAULT_STR_SIZE];
100   pajePushState(SIMIX_get_clock(), "MPI_STATE",
101                 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
102 }
103
104 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
105 {
106   if (!IS_TRACING_SMPI)
107     return;
108
109   char str[INSTR_DEFAULT_STR_SIZE];
110   pajePopState(SIMIX_get_clock(), "MPI_STATE",
111                TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
112 }
113
114 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
115 {
116   if (!IS_TRACING_SMPI)
117     return;
118
119   char str[INSTR_DEFAULT_STR_SIZE];
120   pajePushState(SIMIX_get_clock(), "MPI_STATE",
121                 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
122 }
123
124 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
125 {
126   if (!IS_TRACING_SMPI)
127     return;
128
129   char str[INSTR_DEFAULT_STR_SIZE];
130   pajePopState(SIMIX_get_clock(), "MPI_STATE",
131                TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
132 }
133
134 void TRACE_smpi_send(int rank, int src, int dst)
135 {
136   if (!IS_TRACING_SMPI)
137     return;
138
139   char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
140   TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
141   pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
142                 TRACE_smpi_container(src, str, INSTR_DEFAULT_STR_SIZE), key);
143 }
144
145 void TRACE_smpi_recv(int rank, int src, int dst)
146 {
147   if (!IS_TRACING_SMPI)
148     return;
149
150   char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
151   TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
152   pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
153               TRACE_smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE), key);
154 }
155 #endif