2 This source code file is part of thread_mpi.
3 Written by Sander Pronk, Erik Lindahl, and possibly others.
5 Copyright (c) 2009, Sander Pronk, Erik Lindahl.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 1) Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2) Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3) Neither the name of the copyright holders nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 If you want to redistribute modifications, please consider that
31 scientific software is very special. Version control is crucial -
32 bugs must be traceable. We will be happy to consider code for
33 inclusion in the official distribution, but derived work should not
34 be called official thread_mpi. Details are found in the README & COPYING
39 /* the profiling functions. Many of these are macros, so they're inlined
40 forcibly. Profiling is turned on by defining TMPI_PROFILE, but the most
41 useful parts depend on the cycle counter, which currently only works for
42 x86, x86_64 and ia64. */
45 #include "thread_mpi/atomic/cycles.h"
51 TMPIFN_Send
=0, /* first the point-to-point comm functions */
65 TMPIFN_Barrier
, /* then the barrier */
67 TMPIFN_Bcast
, /* and now the collective comm functions */
81 enum tmpi_wait_functions
83 TMPIWAIT_P2p
, /* p2p send wait */
84 TMPIWAIT_P2p_signal
, /* p2p signaling wait */
85 TMPIWAIT_Coll_send
, /* collective recv wait */
86 TMPIWAIT_Coll_recv
, /* collective recv wait */
87 TMPIWAIT_Barrier
, /* collective recv wait */
88 TMPIWAIT_Reduce
, /* collective (all)reduce wait */
94 /* thread-specific profiling data structure */
97 unsigned long int mpifn_calls
[TMPIFN_Nfunctions
]; /* array of counters */
99 unsigned long int buffered_p2p_xfers
; /* number of buffered p2p transfers */
100 unsigned long int total_p2p_xfers
; /* total number of p2p transfers */
102 unsigned long int buffered_coll_xfers
; /* number of buffered collective
104 unsigned long int total_coll_xfers
; /* total number of collective
107 #ifdef TMPI_CYCLE_COUNT
109 tmpi_cycles_t mpifn_cycles
[TMPIFN_Nfunctions
]; /* array of cycle counters */
110 tmpi_cycles_t wait_cycles
[TMPIWAIT_N
]; /* the wait cycles */
112 tmpi_cycles_t global_start
,global_stop
; /* timing start and stop times */
113 tmpi_cycles_t mpifn_start
; /* individual timing start times for profiling
114 function call times. This can be here
115 because tmpi_profile is thread-specific. */
116 enum tmpi_functions fn
; /* the function being cycle-counted */
119 tmpi_cycles_t wait_start
; /* individual timing start times for profiling
122 double totals
; /* totals counter for reporting end results */
126 extern int tMPI_Profile_started
;
128 /* initialize the profile counter */
129 void tMPI_Profile_init(struct tmpi_profile
*prof
);
133 void tMPI_Profile_destroy(struct tmpi_profile
*prof
);
137 void tMPI_Profile_stop(struct tmpi_profile
*prof
);
141 /* counter functions */
143 #ifdef TMPI_CYCLE_COUNT
144 /*void tMPI_Profile_count_start(struct tmpi_thread *th);*/
145 #define tMPI_Profile_count_start(th) { th->profile.mpifn_start = tmpi_cycles_read(); }
147 #define tMPI_Profile_count_start(th) {}
150 /* end. this is where the counting actually happens */
151 /*void tMPI_Profile_count_stop(struct tmpi_thread *th, enum tmpi_functions fn);*/
152 #ifdef TMPI_CYCLE_COUNT
153 #define tMPI_Profile_count_stop(th, fn) \
155 tmpi_cycles_t stop=tmpi_cycles_read(); \
156 th->profile.mpifn_cycles[fn] += (stop - th->profile.mpifn_start); \
157 (th->profile.mpifn_calls[fn])++; \
160 #define tMPI_Profile_count_stop(th, fn) \
162 (th->profile.mpifn_calls[fn])++; \
173 #ifdef TMPI_CYCLE_COUNT
174 /* start waiting cycle count */
175 /*void tMPI_Profile_wait_start(struct tmpi_thread *th);*/
176 #define tMPI_Profile_wait_start(th) \
178 th->profile.wait_start=tmpi_cycles_read(); \
181 /* stop waiting cycle count */
182 /*void tMPI_Profile_wait_stop(struct tmpi_thread *th,
183 enum tmpi_wait_functions fn);*/
184 #define tMPI_Profile_wait_stop(th, fn)\
186 tmpi_cycles_t wait_stop=tmpi_cycles_read();\
187 th->profile.wait_cycles[fn] += (wait_stop - th->profile.wait_start);\
190 #define tMPI_Profile_wait_start(th) {}
191 #define tMPI_Profile_wait_stop(th, fn) {}
195 /* count the number of transfers at the receiving end. */
196 /*void tMPI_Profile_count_buffered_p2p_xfer(struct tmpi_thread *th);
197 void tMPI_Profile_count_p2p_xfer(struct tmpi_thread *th);
198 void tMPI_Profile_count_buffered_coll_xfer(struct tmpi_thread *th);
199 void tMPI_Profile_count_coll_xfer(struct tmpi_thread *th);*/
200 #define tMPI_Profile_count_buffered_p2p_xfer(th) \
202 (th->profile.buffered_p2p_xfers)++; \
205 #define tMPI_Profile_count_p2p_xfer(th) \
207 (th->profile.total_p2p_xfers)++; \
210 #define tMPI_Profile_count_buffered_coll_xfer(th) \
212 (th->profile.buffered_coll_xfers)++; \
215 #define tMPI_Profile_count_coll_xfer(th) \
217 (th->profile.total_coll_xfers)++; \
222 /* output functions */
223 void tMPI_Profiles_summarize(int Nthreads
, struct tmpi_thread
*threads
);