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 xbt_assert1(xbt_dynar_length(d)!=0,
49 "Trying to get a link key (for message reception) that has no corresponding send (%s).", __FUNCTION__);
50 char *s = xbt_dynar_get_as (d, 0, char *);
51 snprintf (key, n, "%s", s);
52 xbt_dynar_remove_at (d, 0, NULL);
56 static xbt_dict_t process_category;
58 void TRACE_internal_smpi_set_category (const char *category)
60 if (!TRACE_smpi_is_enabled()) return;
63 TRACE_category (category);
65 char processid[INSTR_DEFAULT_STR_SIZE];
66 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
67 if (xbt_dict_get_or_null (process_category, processid))
68 xbt_dict_remove (process_category, processid);
70 xbt_dict_set (process_category, processid, xbt_strdup(category), xbt_free);
73 const char *TRACE_internal_smpi_get_category (void)
75 if (!TRACE_smpi_is_enabled()) return NULL;
77 char processid[INSTR_DEFAULT_STR_SIZE];
78 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
79 return xbt_dict_get_or_null (process_category, processid);
82 void TRACE_smpi_alloc()
84 keys = xbt_dict_new();
85 process_category = xbt_dict_new();
88 void TRACE_smpi_start(void)
90 if (!TRACE_smpi_is_enabled()) return;
95 void TRACE_smpi_release(void)
97 if (!TRACE_smpi_is_enabled()) return;
103 void TRACE_smpi_init(int rank)
105 if (!TRACE_smpi_is_enabled()) return;
107 char str[INSTR_DEFAULT_STR_SIZE];
108 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
111 if (TRACE_smpi_is_grouped()){
112 father = getContainer (SIMIX_host_self_get_name());
114 father = getContainer ("0");
116 xbt_assert2(father!=NULL,
117 "Could not find a parent for mpi rank %s at function %s", str, __FUNCTION__);
118 newContainer(str, INSTR_SMPI, father);
121 void TRACE_smpi_finalize(int rank)
123 if (!TRACE_smpi_is_enabled()) return;
125 char str[INSTR_DEFAULT_STR_SIZE];
126 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
127 destroyContainer(getContainer (str));
130 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
132 if (!TRACE_smpi_is_enabled()) return;
134 char str[INSTR_DEFAULT_STR_SIZE];
135 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
136 container_t container = getContainer (str);
137 type_t type = getType ("MPI_STATE", container->type);
138 val_t value = getValue (operation, "1 1 1", type);
140 new_pajePushState (SIMIX_get_clock(), container, type, value);
143 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
145 if (!TRACE_smpi_is_enabled()) return;
147 char str[INSTR_DEFAULT_STR_SIZE];
148 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
149 container_t container = getContainer (str);
150 type_t type = getType ("MPI_STATE", container->type);
152 new_pajePopState (SIMIX_get_clock(), container, type);
155 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
157 if (!TRACE_smpi_is_enabled()) return;
159 char str[INSTR_DEFAULT_STR_SIZE];
160 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
161 container_t container = getContainer (str);
162 type_t type = getType ("MPI_STATE", container->type);
163 val_t value = getValue (operation, "1 1 1", type);
165 new_pajePushState (SIMIX_get_clock(), container, type, value);
168 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
170 if (!TRACE_smpi_is_enabled()) return;
172 char str[INSTR_DEFAULT_STR_SIZE];
173 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
174 container_t container = getContainer (str);
175 type_t type = getType ("MPI_STATE", container->type);
177 new_pajePopState (SIMIX_get_clock(), container, type);
180 void TRACE_smpi_send(int rank, int src, int dst)
182 if (!TRACE_smpi_is_enabled()) return;
184 char key[INSTR_DEFAULT_STR_SIZE];
185 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
187 char str[INSTR_DEFAULT_STR_SIZE];
188 smpi_container(src, str, INSTR_DEFAULT_STR_SIZE);
189 container_t container = getContainer (str);
190 type_t type = getType ("MPI_LINK", getRootType());
192 new_pajeStartLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
195 void TRACE_smpi_recv(int rank, int src, int dst)
197 if (!TRACE_smpi_is_enabled()) return;
199 char key[INSTR_DEFAULT_STR_SIZE];
200 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
202 char str[INSTR_DEFAULT_STR_SIZE];
203 smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE);
204 container_t container = getContainer (str);
205 type_t type = getType ("MPI_LINK", getRootType());
207 new_pajeEndLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
209 #endif /* HAVE_TRACING */