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 *TRACE_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 void TRACE_smpi_alloc()
57 keys = xbt_dict_new();
60 void TRACE_smpi_start(void)
62 if (TRACE_smpi_is_enabled()) {
67 void TRACE_smpi_release(void)
70 if (TRACE_smpi_is_enabled()) {
75 void TRACE_smpi_init(int rank)
77 if (!TRACE_smpi_is_enabled())
80 char str[INSTR_DEFAULT_STR_SIZE];
81 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
82 if (TRACE_smpi_is_grouped()){
83 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
84 SIMIX_host_self_get_name(), str);
86 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
91 void TRACE_smpi_finalize(int rank)
93 if (!TRACE_smpi_is_enabled())
96 char str[INSTR_DEFAULT_STR_SIZE];
97 pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS",
98 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
101 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
103 if (!TRACE_smpi_is_enabled())
106 char str[INSTR_DEFAULT_STR_SIZE];
107 pajePushState(SIMIX_get_clock(), "MPI_STATE",
108 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
111 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
113 if (!TRACE_smpi_is_enabled())
116 char str[INSTR_DEFAULT_STR_SIZE];
117 pajePopState(SIMIX_get_clock(), "MPI_STATE",
118 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
121 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
123 if (!TRACE_smpi_is_enabled())
126 char str[INSTR_DEFAULT_STR_SIZE];
127 pajePushState(SIMIX_get_clock(), "MPI_STATE",
128 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
131 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
133 if (!TRACE_smpi_is_enabled())
136 char str[INSTR_DEFAULT_STR_SIZE];
137 pajePopState(SIMIX_get_clock(), "MPI_STATE",
138 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
141 void TRACE_smpi_send(int rank, int src, int dst)
143 if (!TRACE_smpi_is_enabled())
146 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
147 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
148 pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
149 TRACE_smpi_container(src, str, INSTR_DEFAULT_STR_SIZE), key);
152 void TRACE_smpi_recv(int rank, int src, int dst)
154 if (!TRACE_smpi_is_enabled())
157 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
158 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
159 pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
160 TRACE_smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE), key);
162 #endif /* HAVE_TRACING */