1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_smpi, instr, "Tracing SMPI");
13 static xbt_dict_t keys;
15 static char *smpi_container(int rank, char *container, int n)
17 snprintf(container, n, "rank-%d", rank);
21 static char *TRACE_smpi_put_key(int src, int dst, char *key, int n)
23 //get the dynar for src#dst
24 char aux[INSTR_DEFAULT_STR_SIZE];
25 snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d", src, dst);
26 xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
28 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
29 xbt_dict_set(keys, aux, d, xbt_free);
32 static unsigned long long counter = 0;
33 snprintf(key, n, "%d%d%lld", src, dst, counter++);
36 char *a = (char*)xbt_strdup(key);
37 xbt_dynar_push_as(d, char *, a);
42 static char *TRACE_smpi_get_key(int src, int dst, char *key, int n)
44 char aux[INSTR_DEFAULT_STR_SIZE];
45 snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d", src, dst);
46 xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
48 int length = xbt_dynar_length(d);
49 char *s = xbt_dynar_get_as (d, length-1, char *);
50 snprintf (key, n, "%s", s);
51 xbt_dynar_remove_at (d, length-1, NULL);
55 static xbt_dict_t process_category;
57 void TRACE_internal_smpi_set_category (const char *category)
59 if (!TRACE_is_active())
61 if (!TRACE_smpi_is_enabled())
65 TRACE_category (category);
67 char processid[INSTR_DEFAULT_STR_SIZE];
68 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
69 if (xbt_dict_get_or_null (process_category, processid))
70 xbt_dict_remove (process_category, processid);
72 xbt_dict_set (process_category, processid, xbt_strdup(category), xbt_free);
75 const char *TRACE_internal_smpi_get_category (void)
77 if (!TRACE_is_active())
79 if (!TRACE_smpi_is_enabled())
82 char processid[INSTR_DEFAULT_STR_SIZE];
83 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
84 return xbt_dict_get_or_null (process_category, processid);
87 void TRACE_smpi_alloc()
89 keys = xbt_dict_new();
90 process_category = xbt_dict_new();
93 void TRACE_smpi_start(void)
95 if (TRACE_is_enabled()) {
100 void TRACE_smpi_release(void)
102 if (TRACE_is_enabled()) {
103 TRACE_surf_release();
108 void TRACE_smpi_init(int rank)
110 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
113 char str[INSTR_DEFAULT_STR_SIZE];
114 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
117 if (TRACE_smpi_is_grouped()){
118 father = getContainer (SIMIX_host_self_get_name());
120 father = getContainer ("0");
122 xbt_assert2(father!=NULL,
123 "Could not find a parent for mpi rank %s at function %s", str, __FUNCTION__);
124 newContainer(str, INSTR_SMPI, father);
127 void TRACE_smpi_finalize(int rank)
129 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
132 char str[INSTR_DEFAULT_STR_SIZE];
133 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
134 destroyContainer(getContainer (str));
137 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
139 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
142 char str[INSTR_DEFAULT_STR_SIZE];
143 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
144 container_t container = getContainer (str);
145 type_t type = getType ("MPI_STATE");
147 new_pajePushState (SIMIX_get_clock(), container, type, operation);
150 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
152 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
155 char str[INSTR_DEFAULT_STR_SIZE];
156 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
157 container_t container = getContainer (str);
158 type_t type = getType ("MPI_STATE");
160 new_pajePopState (SIMIX_get_clock(), container, type);
163 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
165 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
168 char str[INSTR_DEFAULT_STR_SIZE];
169 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
170 container_t container = getContainer (str);
171 type_t type = getType ("MPI_STATE");
173 new_pajePushState (SIMIX_get_clock(), container, type, operation);
176 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
178 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
181 char str[INSTR_DEFAULT_STR_SIZE];
182 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
183 container_t container = getContainer (str);
184 type_t type = getType ("MPI_STATE");
186 new_pajePopState (SIMIX_get_clock(), container, type);
189 void TRACE_smpi_send(int rank, int src, int dst)
191 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
194 char key[INSTR_DEFAULT_STR_SIZE];
195 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
197 char str[INSTR_DEFAULT_STR_SIZE];
198 smpi_container(src, str, INSTR_DEFAULT_STR_SIZE);
199 container_t container = getContainer (str);
200 type_t type = getType ("MPI_LINK");
202 new_pajeStartLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
205 void TRACE_smpi_recv(int rank, int src, int dst)
207 if (!(TRACE_is_active() && TRACE_smpi_is_enabled()))
210 char key[INSTR_DEFAULT_STR_SIZE];
211 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
213 char str[INSTR_DEFAULT_STR_SIZE];
214 smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE);
215 container_t container = getContainer (str);
216 type_t type = getType ("MPI_LINK");
218 new_pajeEndLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
220 #endif /* HAVE_TRACING */