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
22 char aux[INSTR_DEFAULT_STR_SIZE];
23 snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%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_ref);
27 xbt_dict_set(keys, aux, d, xbt_free);
30 static unsigned long long counter = 0;
31 snprintf(key, n, "%d%d%lld", src, dst, counter++);
34 char *a = (char*)xbt_strdup(key);
35 xbt_dynar_push_as(d, char *, a);
40 static char *TRACE_smpi_get_key(int src, int dst, char *key, int n)
42 char aux[INSTR_DEFAULT_STR_SIZE];
43 snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d", src, dst);
44 xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
46 int length = xbt_dynar_length(d);
47 char *s = xbt_dynar_get_as (d, length-1, char *);
48 snprintf (key, n, "%s", s);
49 xbt_dynar_remove_at (d, length-1, NULL);
53 void TRACE_smpi_alloc()
55 keys = xbt_dict_new();
58 void TRACE_smpi_start(void)
60 if (IS_TRACING_SMPI) {
65 void TRACE_smpi_release(void)
68 if (IS_TRACING_SMPI) {
73 void TRACE_smpi_init(int rank)
78 char str[INSTR_DEFAULT_STR_SIZE];
79 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
80 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
81 SIMIX_host_get_name(SIMIX_host_self()), str);
84 void TRACE_smpi_finalize(int rank)
89 char str[INSTR_DEFAULT_STR_SIZE];
90 pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS",
91 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
94 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
99 char str[INSTR_DEFAULT_STR_SIZE];
100 pajePushState(SIMIX_get_clock(), "MPI_STATE",
101 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
104 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
106 if (!IS_TRACING_SMPI)
109 char str[INSTR_DEFAULT_STR_SIZE];
110 pajePopState(SIMIX_get_clock(), "MPI_STATE",
111 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
114 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
116 if (!IS_TRACING_SMPI)
119 char str[INSTR_DEFAULT_STR_SIZE];
120 pajePushState(SIMIX_get_clock(), "MPI_STATE",
121 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
124 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
126 if (!IS_TRACING_SMPI)
129 char str[INSTR_DEFAULT_STR_SIZE];
130 pajePopState(SIMIX_get_clock(), "MPI_STATE",
131 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
134 void TRACE_smpi_send(int rank, int src, int dst)
136 if (!IS_TRACING_SMPI)
139 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
140 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
141 pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
142 TRACE_smpi_container(src, str, INSTR_DEFAULT_STR_SIZE), key);
145 void TRACE_smpi_recv(int rank, int src, int dst)
147 if (!IS_TRACING_SMPI)
150 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
151 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
152 pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
153 TRACE_smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE), key);