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_init ()
52 keys = xbt_dict_new();
55 void TRACE_smpi_start (void)
62 void TRACE_smpi_end (void)
69 void TRACE_smpi_init (int rank)
71 if (!IS_TRACING_SMPI) return;
74 _TRACE_smpi_container (rank, str, 100);
75 pajeCreateContainer (SIMIX_get_clock(), str, "MPI_PROCESS",
76 SIMIX_host_get_name(SIMIX_host_self()), str);
79 void TRACE_smpi_finalize (int rank)
81 if (!IS_TRACING_SMPI) return;
84 pajeDestroyContainer (SIMIX_get_clock(), "MPI_PROCESS",
85 _TRACE_smpi_container (rank, str, 100));
88 void TRACE_smpi_collective_in (int rank, int root, const char *operation)
90 if (!IS_TRACING_SMPI) return;
93 pajePushState (SIMIX_get_clock(), "MPI_STATE",
94 _TRACE_smpi_container (rank, str, 100), operation);
97 void TRACE_smpi_collective_out (int rank, int root, const char *operation)
99 if (!IS_TRACING_SMPI) return;
102 pajePopState (SIMIX_get_clock(), "MPI_STATE",
103 _TRACE_smpi_container (rank, str, 100));
106 void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation)
108 if (!IS_TRACING_SMPI) return;
111 pajePushState (SIMIX_get_clock(), "MPI_STATE",
112 _TRACE_smpi_container (rank, str, 100), operation);
115 void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation)
117 if (!IS_TRACING_SMPI) return;
120 pajePopState (SIMIX_get_clock(), "MPI_STATE",
121 _TRACE_smpi_container (rank, str, 100));
124 void TRACE_smpi_send (int rank, int src, int dst)
126 if (!IS_TRACING_SMPI) return;
128 char key[100], str[100];
129 _TRACE_smpi_put_key (src, dst, key, 100);
130 pajeStartLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
131 _TRACE_smpi_container (src, str, 100), key);
134 void TRACE_smpi_recv (int rank, int src, int dst)
136 if (!IS_TRACING_SMPI) return;
138 char key[100], str[100];
139 _TRACE_smpi_get_key (src, dst, key, 100);
140 pajeEndLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
141 _TRACE_smpi_container (dst, str, 100), key);