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_smpi_is_enabled()) return;
62 TRACE_category (category);
64 char processid[INSTR_DEFAULT_STR_SIZE];
65 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
66 if (xbt_dict_get_or_null (process_category, processid))
67 xbt_dict_remove (process_category, processid);
69 xbt_dict_set (process_category, processid, xbt_strdup(category), xbt_free);
72 const char *TRACE_internal_smpi_get_category (void)
74 if (!TRACE_smpi_is_enabled()) return NULL;
76 char processid[INSTR_DEFAULT_STR_SIZE];
77 snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
78 return xbt_dict_get_or_null (process_category, processid);
81 void TRACE_smpi_alloc()
83 keys = xbt_dict_new();
84 process_category = xbt_dict_new();
87 void TRACE_smpi_start(void)
89 if (!TRACE_smpi_is_enabled()) return;
94 void TRACE_smpi_release(void)
96 if (!TRACE_smpi_is_enabled()) return;
102 void TRACE_smpi_init(int rank)
104 if (!TRACE_smpi_is_enabled()) return;
106 char str[INSTR_DEFAULT_STR_SIZE];
107 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
110 if (TRACE_smpi_is_grouped()){
111 father = getContainer (SIMIX_host_self_get_name());
113 father = getContainer ("0");
115 xbt_assert2(father!=NULL,
116 "Could not find a parent for mpi rank %s at function %s", str, __FUNCTION__);
117 newContainer(str, INSTR_SMPI, father);
120 void TRACE_smpi_finalize(int rank)
122 if (!TRACE_smpi_is_enabled()) return;
124 char str[INSTR_DEFAULT_STR_SIZE];
125 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
126 destroyContainer(getContainer (str));
129 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
131 if (!TRACE_smpi_is_enabled()) return;
133 char str[INSTR_DEFAULT_STR_SIZE];
134 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
135 container_t container = getContainer (str);
136 type_t type = getType ("MPI_STATE");
138 new_pajePushState (SIMIX_get_clock(), container, type, operation);
141 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
143 if (!TRACE_smpi_is_enabled()) return;
145 char str[INSTR_DEFAULT_STR_SIZE];
146 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
147 container_t container = getContainer (str);
148 type_t type = getType ("MPI_STATE");
150 new_pajePopState (SIMIX_get_clock(), container, type);
153 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
155 if (!TRACE_smpi_is_enabled()) return;
157 char str[INSTR_DEFAULT_STR_SIZE];
158 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
159 container_t container = getContainer (str);
160 type_t type = getType ("MPI_STATE");
162 new_pajePushState (SIMIX_get_clock(), container, type, operation);
165 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
167 if (!TRACE_smpi_is_enabled()) return;
169 char str[INSTR_DEFAULT_STR_SIZE];
170 smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
171 container_t container = getContainer (str);
172 type_t type = getType ("MPI_STATE");
174 new_pajePopState (SIMIX_get_clock(), container, type);
177 void TRACE_smpi_send(int rank, int src, int dst)
179 if (!TRACE_smpi_is_enabled()) return;
181 char key[INSTR_DEFAULT_STR_SIZE];
182 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
184 char str[INSTR_DEFAULT_STR_SIZE];
185 smpi_container(src, str, INSTR_DEFAULT_STR_SIZE);
186 container_t container = getContainer (str);
187 type_t type = getType ("MPI_LINK");
189 new_pajeStartLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
192 void TRACE_smpi_recv(int rank, int src, int dst)
194 if (!TRACE_smpi_is_enabled()) return;
196 char key[INSTR_DEFAULT_STR_SIZE];
197 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
199 char str[INSTR_DEFAULT_STR_SIZE];
200 smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE);
201 container_t container = getContainer (str);
202 type_t type = getType ("MPI_LINK");
204 new_pajeEndLink (SIMIX_get_clock(), getRootContainer(), type, container, "PTP", key);
206 #endif /* HAVE_TRACING */