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/private.h"
11 static xbt_dict_t keys;
13 static char *TRACE_smpi_container(int rank, char *container, int n)
15 snprintf(container, n, "rank-%d", rank);
19 static char *TRACE_smpi_put_key(int src, int dst, char *key, int n)
21 //get the dynar for src#dst
23 snprintf(aux, 100, "%d#%d", src, dst);
24 xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
26 d = xbt_dynar_new(sizeof(char *), xbt_free);
27 xbt_dict_set(keys, aux, d, xbt_free);
30 static long long counter = 0;
31 snprintf(key, n, "%d%d%lld", src, dst, counter++);
33 xbt_dynar_insert_at(d, 0, xbt_strdup(key));
37 static char *TRACE_smpi_get_key(int src, int dst, char *key, int n)
40 snprintf(aux, 100, "%d#%d", src, dst);
41 xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
43 int length = xbt_dynar_length(d);
45 xbt_dynar_remove_at(d, length - 1, stored_key);
46 strncpy(key, stored_key, n);
50 void TRACE_smpi_alloc()
52 keys = xbt_dict_new();
55 void TRACE_smpi_start(void)
57 if (IS_TRACING_SMPI) {
62 void TRACE_smpi_release(void)
65 if (IS_TRACING_SMPI) {
70 void TRACE_smpi_init(int rank)
76 TRACE_smpi_container(rank, str, 100);
77 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
78 SIMIX_host_get_name(SIMIX_host_self()), str);
81 void TRACE_smpi_finalize(int rank)
87 pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS",
88 TRACE_smpi_container(rank, str, 100));
91 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
97 pajePushState(SIMIX_get_clock(), "MPI_STATE",
98 TRACE_smpi_container(rank, str, 100), operation);
101 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
103 if (!IS_TRACING_SMPI)
107 pajePopState(SIMIX_get_clock(), "MPI_STATE",
108 TRACE_smpi_container(rank, str, 100));
111 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
113 if (!IS_TRACING_SMPI)
117 pajePushState(SIMIX_get_clock(), "MPI_STATE",
118 TRACE_smpi_container(rank, str, 100), operation);
121 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
123 if (!IS_TRACING_SMPI)
127 pajePopState(SIMIX_get_clock(), "MPI_STATE",
128 TRACE_smpi_container(rank, str, 100));
131 void TRACE_smpi_send(int rank, int src, int dst)
133 if (!IS_TRACING_SMPI)
136 char key[100], str[100];
137 TRACE_smpi_put_key(src, dst, key, 100);
138 pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
139 TRACE_smpi_container(src, str, 100), key);
142 void TRACE_smpi_recv(int rank, int src, int dst)
144 if (!IS_TRACING_SMPI)
147 char key[100], str[100];
148 TRACE_smpi_get_key(src, dst, key, 100);
149 pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
150 TRACE_smpi_container(dst, str, 100), key);