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)
70 void TRACE_smpi_init (int rank)
72 if (!IS_TRACING_SMPI) return;
75 _TRACE_smpi_container (rank, str, 100);
76 pajeCreateContainer (SIMIX_get_clock(), str, "MPI_PROCESS",
77 SIMIX_host_get_name(SIMIX_host_self()), str);
80 void TRACE_smpi_finalize (int rank)
82 if (!IS_TRACING_SMPI) return;
85 pajeDestroyContainer (SIMIX_get_clock(), "MPI_PROCESS",
86 _TRACE_smpi_container (rank, str, 100));
89 void TRACE_smpi_collective_in (int rank, int root, const char *operation)
91 if (!IS_TRACING_SMPI) return;
94 pajePushState (SIMIX_get_clock(), "MPI_STATE",
95 _TRACE_smpi_container (rank, str, 100), operation);
98 void TRACE_smpi_collective_out (int rank, int root, const char *operation)
100 if (!IS_TRACING_SMPI) return;
103 pajePopState (SIMIX_get_clock(), "MPI_STATE",
104 _TRACE_smpi_container (rank, str, 100));
107 void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation)
109 if (!IS_TRACING_SMPI) return;
112 pajePushState (SIMIX_get_clock(), "MPI_STATE",
113 _TRACE_smpi_container (rank, str, 100), operation);
116 void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation)
118 if (!IS_TRACING_SMPI) return;
121 pajePopState (SIMIX_get_clock(), "MPI_STATE",
122 _TRACE_smpi_container (rank, str, 100));
125 void TRACE_smpi_send (int rank, int src, int dst)
127 if (!IS_TRACING_SMPI) return;
129 char key[100], str[100];
130 _TRACE_smpi_put_key (src, dst, key, 100);
131 pajeStartLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
132 _TRACE_smpi_container (src, str, 100), key);
135 void TRACE_smpi_recv (int rank, int src, int dst)
137 if (!IS_TRACING_SMPI) return;
139 char key[100], str[100];
140 _TRACE_smpi_get_key (src, dst, key, 100);
141 pajeEndLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
142 _TRACE_smpi_container (dst, str, 100), key);