Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add gatherv replay action (bigdft can be replayed easily now)
[simgrid.git] / src / instr / instr_TI_trace.c
1 /* Copyright (c) 2010-2013. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6 #include "instr/instr_private.h"
7 #include "xbt/virtu.h" /* sg_cmdline */
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_TI_trace, instr_trace, "tracing event system");
9
10
11 extern FILE *tracing_file;
12 extern s_instr_trace_writer_t active_writer;
13 extern xbt_dynar_t buffer;
14
15 void TRACE_TI_init(void)
16 {
17   active_writer.print_PushState = print_TIPushState;
18 }
19
20 void TRACE_TI_start(void)
21 {
22   char *filename = TRACE_get_filename();
23   tracing_file = fopen(filename, "w");
24   if (tracing_file == NULL) {
25     THROWF(system_error, 1, "Tracefile %s could not be opened for writing.",
26            filename);
27   }
28
29   XBT_DEBUG("Filename %s is open for writing", filename);
30
31   /* output one line comment */
32   dump_comment(TRACE_get_comment());
33
34   /* output comment file */
35   dump_comment_file(TRACE_get_comment_file());
36
37   buffer = xbt_dynar_new(sizeof(paje_event_t), NULL);
38 }
39
40 void TRACE_TI_end(void)
41 {
42   fclose(tracing_file);
43   char *filename = TRACE_get_filename();
44   xbt_dynar_free(&buffer);
45   XBT_DEBUG("Filename %s is closed", filename);
46 }
47
48 void print_TIPushState(paje_event_t event)
49 {
50
51
52   int i;
53
54   //char* function=NULL;
55   if (((pushState_t) event->data)->extra == NULL)
56     return;
57   instr_extra_data extra =
58       (instr_extra_data) (((pushState_t) event->data)->extra);
59
60   char *process_id = NULL;
61   //FIXME: dirty extract "rank-" from the name, as we want the bare process id here
62   if (strstr(((pushState_t) event->data)->container->name, "rank-") == NULL)
63     process_id = xbt_strdup(((pushState_t) event->data)->container->name);
64   else
65     process_id = xbt_strdup(((pushState_t) event->data)->container->name + 5);
66
67   switch (extra->type) {
68
69   case TRACING_INIT:
70     fprintf(tracing_file, "%s init\n", process_id);
71     break;
72   case TRACING_FINALIZE:
73     fprintf(tracing_file, "%s finalize\n", process_id);
74     break;
75   case TRACING_SEND:
76     fprintf(tracing_file, "%s send %d %d %s\n", process_id, extra->dst,
77             extra->send_size, extra->datatype1);
78     break;
79   case TRACING_ISEND:
80     fprintf(tracing_file, "%s isend %d %d %s\n", process_id, extra->dst,
81             extra->send_size, extra->datatype1);
82     break;
83   case TRACING_RECV:
84     fprintf(tracing_file, "%s recv %d %d %s\n", process_id, extra->src,
85             extra->send_size, extra->datatype1);
86     break;
87   case TRACING_IRECV:
88     fprintf(tracing_file, "%s irecv %d %d %s\n", process_id, extra->src,
89             extra->send_size, extra->datatype1);
90     break;
91   case TRACING_WAIT:
92     fprintf(tracing_file, "%s wait\n", process_id);
93     break;
94   case TRACING_WAITALL:
95     fprintf(tracing_file, "%s waitall\n", process_id);
96     break;
97   case TRACING_BARRIER:
98     fprintf(tracing_file, "%s barrier\n", process_id);
99     break;
100   case TRACING_BCAST:          // rank bcast size (root) (datatype)
101     fprintf(tracing_file, "%s bcast %d ", process_id, extra->send_size);
102     if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
103       fprintf(tracing_file, "%d %s", extra->root, extra->datatype1);
104     fprintf(tracing_file, "\n");
105     break;
106   case TRACING_REDUCE:         // rank reduce comm_size comp_size (root) (datatype)
107     fprintf(tracing_file, "%s reduce %d %f ", process_id, extra->send_size,
108             extra->comp_size);
109     if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
110       fprintf(tracing_file, "%d %s", extra->root, extra->datatype1);
111     fprintf(tracing_file, "\n");
112     break;
113   case TRACING_ALLREDUCE:      // rank allreduce comm_size comp_size (datatype)
114     fprintf(tracing_file, "%s allreduce %d %f %s\n", process_id,
115             extra->send_size, extra->comp_size, extra->datatype1);
116     break;
117   case TRACING_ALLTOALL:       // rank alltoall send_size recv_size (sendtype) (recvtype)
118     fprintf(tracing_file, "%s alltoall %d %d %s %s\n", process_id,
119             extra->send_size, extra->recv_size, extra->datatype1,
120             extra->datatype2);
121     break;
122   case TRACING_ALLTOALLV:      // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
123     fprintf(tracing_file, "%s alltoallv %d ", process_id, extra->send_size);
124     for (i = 0; i < extra->num_processes; i++)
125       fprintf(tracing_file, "%d ", extra->sendcounts[i]);
126     fprintf(tracing_file, "%d ", extra->recv_size);
127     for (i = 0; i < extra->num_processes; i++)
128       fprintf(tracing_file, "%d ", extra->recvcounts[i]);
129     fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
130     break;
131   case TRACING_GATHER:         // rank gather send_size recv_size root (sendtype) (recvtype)
132     fprintf(tracing_file, "%s gather %d %d %d %s %s\n", process_id,
133             extra->send_size, extra->recv_size, extra->root, extra->datatype1,
134             extra->datatype2);
135     break;
136   case TRACING_ALLGATHERV:     // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
137     fprintf(tracing_file, "%s allgatherv %d ", process_id, extra->send_size);
138     for (i = 0; i < extra->num_processes; i++)
139       fprintf(tracing_file, "%d ", extra->recvcounts[i]);
140     fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
141     break;
142   case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
143     fprintf(tracing_file, "%s reducescatter ", process_id);
144     for (i = 0; i < extra->num_processes; i++)
145       fprintf(tracing_file, "%d ", extra->recvcounts[i]);
146     fprintf(tracing_file, "%f %s\n", extra->comp_size, extra->datatype1);
147     break;
148   case TRACING_COMPUTING:
149     fprintf(tracing_file, "%s compute %f\n", process_id, extra->comp_size);
150     break;
151   case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
152     fprintf(tracing_file, "%s gatherv %d ", process_id, extra->send_size);
153     for (i = 0; i < extra->num_processes; i++)
154       fprintf(tracing_file, "%d ", extra->recvcounts[i]);
155     fprintf(tracing_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
156     break;
157   case TRACING_WAITANY:
158   case TRACING_SENDRECV:
159   case TRACING_SCATTER:
160   case TRACING_SCATTERV:
161   case TRACING_ALLGATHER:
162   case TRACING_SCAN:
163   case TRACING_EXSCAN:
164   case TRACING_COMM_SIZE:
165   case TRACING_COMM_SPLIT:
166   case TRACING_COMM_DUP:
167   case TRACING_SSEND:
168   case TRACING_ISSEND:
169   default:
170
171     XBT_WARN
172         ("Call from %s impossible to translate into replay command : Not implemented (yet)",
173          ((pushState_t) event->data)->value->name);
174     break;
175   }
176
177   if (extra->recvcounts != NULL)
178     xbt_free(extra->recvcounts);
179   if (extra->sendcounts != NULL)
180     xbt_free(extra->sendcounts);
181   xbt_free(process_id);
182   xbt_free(extra);
183 }