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 if (TRACE_smpi_is_grouped()){
81 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
82 SIMIX_host_get_name(SIMIX_host_self()), str);
84 pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS",
89 void TRACE_smpi_finalize(int rank)
94 char str[INSTR_DEFAULT_STR_SIZE];
95 pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS",
96 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
99 void TRACE_smpi_collective_in(int rank, int root, const char *operation)
101 if (!IS_TRACING_SMPI)
104 char str[INSTR_DEFAULT_STR_SIZE];
105 pajePushState(SIMIX_get_clock(), "MPI_STATE",
106 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
109 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
111 if (!IS_TRACING_SMPI)
114 char str[INSTR_DEFAULT_STR_SIZE];
115 pajePopState(SIMIX_get_clock(), "MPI_STATE",
116 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
119 void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation)
121 if (!IS_TRACING_SMPI)
124 char str[INSTR_DEFAULT_STR_SIZE];
125 pajePushState(SIMIX_get_clock(), "MPI_STATE",
126 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE), operation);
129 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
131 if (!IS_TRACING_SMPI)
134 char str[INSTR_DEFAULT_STR_SIZE];
135 pajePopState(SIMIX_get_clock(), "MPI_STATE",
136 TRACE_smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
139 void TRACE_smpi_send(int rank, int src, int dst)
141 if (!IS_TRACING_SMPI)
144 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
145 TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
146 pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
147 TRACE_smpi_container(src, str, INSTR_DEFAULT_STR_SIZE), key);
150 void TRACE_smpi_recv(int rank, int src, int dst)
152 if (!IS_TRACING_SMPI)
155 char key[INSTR_DEFAULT_STR_SIZE], str[INSTR_DEFAULT_STR_SIZE];
156 TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
157 pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP",
158 TRACE_smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE), key);