PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
timer.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5  Author: Edgar Solomonik and Mathias Jacquelin
6 
7  This file is part of Cyclops Tensor Framework (CTF) and PEXSI. All rights
8  reserved.
9 
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions are met:
12 
13  (1) Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15  (2) Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18  (3) Neither the name of the University of California, Lawrence Berkeley
19  National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
20  be used to endorse or promote products derived from this software without
21  specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
27  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  You are under no obligation whatsoever to provide any bug fixes, patches, or
35  upgrades to the features, functionality or performance of the source code
36  ("Enhancements") to anyone; however, if you choose to make your Enhancements
37  available either publicly, or directly to Lawrence Berkeley National
38  Laboratory, without imposing a separate written license agreement for such
39  Enhancements, then you hereby grant the following license: a non-exclusive,
40  royalty-free perpetual license to install, use, modify, prepare derivative
41  works, incorporate into other computer software, distribute, and sublicense
42  such enhancements or derivative works thereof, in binary and source code form.
43 */
47 #ifndef _PEXSI_TIMER_H_
48 #define _PEXSI_TIMER_H_
49 
50 #ifdef __cplusplus
51 #define VAL(str) #str
52 #define TOSTRING(str) VAL(str)
53 
54 #ifdef USE_TAU
55 #include "pexsi/TAU.h"
56 #define TIMER_START(a) TAU_START(TOSTRING(a));
57 #define TIMER_STOP(a) TAU_STOP(TOSTRING(a));
58 
59 #elif defined (PROFILE) || defined(PMPI)
60 #define TAU
61 #define TIMER_START(a) TAU_FSTART(a);
62 #define TIMER_STOP(a) TAU_FSTOP(a);
63 
64 #else
65 
66 #define TIMER_START(a)
67 #define TIMER_STOP(a)
68 #endif
69 
70 
71 
72 #include <mpi.h>
73 
74 
75 class CTF_timer{
76  public:
77  char const * timer_name;
78  int index;
79  int exited;
80  int original;
81 
82  public:
83  CTF_timer(char const * name);
84  ~CTF_timer();
85  void stop();
86  void start();
87  void exit();
88 
89 };
90 
91 void CTF_set_main_args(int argc, char * const * argv);
92 void CTF_set_context(MPI_Comm ctxt);
93 
94 #ifdef TAU
95 #define TAU_FSTART(ARG) \
96  do { CTF_timer t(#ARG); t.start(); } while (0);
97 
98 #define TAU_FSTOP(ARG) \
99  do { CTF_timer t(#ARG); t.stop(); } while (0);
100 
101 #define TAU_PROFILE_TIMER(ARG1, ARG2, ARG3, ARG4)
102 
103 #ifdef __cplusplus
104 extern "C"{
105 #endif
106 void TAU_PROFILE_INIT(int argc, char ** argv);
107 void TAU_PROFILE_SET_CONTEXT(MPI_Comm comm);
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 
113 #define TAU_PROFILE_SET_NODE(ARG)
114 
115 #define TAU_PROFILE_START(ARG) \
116  CTF_timer __CTF_timer##ARG(#ARG);
117 
118 #define TAU_PROFILE_STOP(ARG) \
119  __CTF_timer##ARG.stop();
120 
121 
122 #endif
123 
124 #ifdef PMPI
125 #define MPI_Bcast(...) \
126  { CTF_timer __t("MPI_Bcast"); \
127  __t.start(); \
128  PMPI_Bcast(__VA_ARGS__); \
129  __t.stop(); }
130 #define MPI_Reduce(...) \
131  { CTF_timer __t("MPI_Reduce"); \
132  __t.start(); \
133  PMPI_Reduce(__VA_ARGS__); \
134  __t.stop(); }
135 #define MPI_Wait(...) \
136  { CTF_timer __t("MPI_Wait"); \
137  __t.start(); \
138  PMPI_Wait(__VA_ARGS__); \
139  __t.stop(); }
140 #define MPI_Send(...) \
141  { CTF_timer __t("MPI_Send"); \
142  __t.start(); \
143  PMPI_Send(__VA_ARGS__); \
144  __t.stop(); }
145 #define MPI_Allreduce(...) \
146  { CTF_timer __t("MPI_Allreduce"); \
147  __t.start(); \
148  PMPI_Allreduce(__VA_ARGS__); \
149  __t.stop(); }
150 #define MPI_Allgather(...) \
151  { CTF_timer __t("MPI_Allgather"); \
152  __t.start(); \
153  PMPI_Allgather(__VA_ARGS__); \
154  __t.stop(); }
155 #define MPI_Scatter(...) \
156  { CTF_timer __t("MPI_Scatter"); \
157  __t.start(); \
158  PMPI_Scatter(__VA_ARGS__); \
159  __t.stop(); }
160 #define MPI_Alltoall(...) \
161  { CTF_timer __t("MPI_Alltoall"); \
162  __t.start(); \
163  PMPI_Alltoall(__VA_ARGS__); \
164  __t.stop(); }
165 #define MPI_Alltoallv(...) \
166  { CTF_timer __t("MPI_Alltoallv"); \
167  __t.start(); \
168  PMPI_Alltoallv(__VA_ARGS__); \
169  __t.stop(); }
170 #define MPI_Gatherv(...) \
171  { CTF_timer __t("MPI_Gatherv"); \
172  __t.start(); \
173  PMPI_Gatherv(__VA_ARGS__); \
174  __t.stop(); }
175 #define MPI_Scatterv(...) \
176  { CTF_timer __t("MPI_Scatterv"); \
177  __t.start(); \
178  PMPI_Scatterv(__VA_ARGS__); \
179  __t.stop(); }
180 #define MPI_Waitall(...) \
181  { CTF_timer __t("MPI_Waitall"); \
182  __t.start(); \
183  PMPI_Waitall(__VA_ARGS__); \
184  __t.stop(); }
185 #define MPI_Barrier(...) \
186  { CTF_timer __t("MPI_Barrier"); \
187  __t.start(); \
188  PMPI_Barrier(__VA_ARGS__); \
189  __t.stop(); }
190 #endif
191 
192 #endif
193 #endif //_PEXSI_TIMER_H_
194