HPCToolkit
mpi.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 
48 /******************************************************************************
49  * system includes
50  *****************************************************************************/
51 
52 #include <stdlib.h>
53 #include <stddef.h>
54 #include <string.h>
55 #include <assert.h>
56 #include <unistd.h>
57 
58 
59 
60 /******************************************************************************
61  * libmonitor
62  *****************************************************************************/
63 
64 #include <monitor.h>
65 
66 
67 
68 /******************************************************************************
69  * local includes
70  *****************************************************************************/
71 
72 #include <hpcrun/hpcrun_options.h>
73 #include <hpcrun/disabled.h>
74 #include <hpcrun/metrics.h>
75 #include <sample_event.h>
76 #include "sample_source_obj.h"
77 #include "common.h"
78 #include <main.h>
80 #include "simple_oo.h"
81 #include <hpcrun/thread_data.h>
82 
83 #include <messages/messages.h>
84 
85 
86 static int hpmpi_metric_id = -1;
87 
88 /******************************************************************************
89  * method definitions
90  *****************************************************************************/
91 
92 static void
93 METHOD_FN(init)
94 {
95  self->state = INIT;
96 }
97 
98 
99 static void
100 METHOD_FN(thread_init)
101 {
102  TMSG(MPI, "thread init (no action needed)");
103 }
104 
105 static void
106 METHOD_FN(thread_init_action)
107 {
108  TMSG(MPI, "thread action (noop)");
109 }
110 
111 static void
112 METHOD_FN(start)
113 {
114  TMSG(MPI,"starting MPI");
115 
116  TD_GET(ss_state)[self->sel_idx] = START;
117 }
118 
119 static void
120 METHOD_FN(thread_fini_action)
121 {
122  TMSG(MPI, "thread fini (noop)");
123 }
124 
125 static void
127 {
128  TMSG(MPI,"stopping MPI");
129  TD_GET(ss_state)[self->sel_idx] = STOP;
130 }
131 
132 
133 static void
134 METHOD_FN(shutdown)
135 {
136  METHOD_CALL(self,stop); // make sure stop has been called
137  self->state = UNINIT;
138 }
139 
140 
141 static bool
142 METHOD_FN(supports_event,const char *ev_str)
143 {
144  return hpcrun_ev_is(ev_str,"MPI_MSG");
145 }
146 
147 
148 // MPI_MSG creates one metrics: bytes sent/received in bytes
149 
150 static void
151 METHOD_FN(process_event_list,int lush_metrics)
152 {
154 
155  TMSG(MPI, "Setting up metrics for MPI: %d", hpmpi_metric_id);
156 
158 }
159 
160 
161 //
162 // Event sets not relevant for this sample source
163 // Events are generated by user code
164 //
165 static void
166 METHOD_FN(gen_event_set,int lush_metrics)
167 {
168 }
169 
170 
171 //
172 //
173 //
174 static void
175 METHOD_FN(display_events)
176 {
177  printf("===========================================================================\n");
178  printf("Available MPI events\n");
179  printf("===========================================================================\n");
180  printf("Name\t\tDescription\n");
181  printf("---------------------------------------------------------------------------\n");
182  printf("MPI_MSG\t\tThe number of bytes for all sent/received messages\n");
183  printf("\n");
184 }
185 
186 /***************************************************************************
187  * object
188  ***************************************************************************/
189 
190 //
191 // sync class is "SS_SOFTWARE" so that both synchronous and asynchronous sampling is possible
192 //
193 
194 #define ss_name hpmpi
195 #define ss_cls SS_SOFTWARE
196 
197 #include "ss_obj.h"
198 
199 
200 // ***************************************************************************
201 // Interface functions
202 // ***************************************************************************
203 
204 // increment the return count
205 //
206 // N.B. : This function is necessary to avoid exposing the retcnt_obj.
207 // For the case of the retcnt sample source, the handler (the trampoline)
208 // is separate from the sample source code.
209 // Consequently, the interaction with metrics must be done procedurally
210 
211 int
213 {
214  return hpmpi_metric_id;
215 }
216 
217 
218 
219 void
221 {
222  if (node != NULL) {
223  TMSG(MPI, "\tmpi (cct node %p): metric[%d] += %d",
224  node, hpmpi_metric_id, incr);
226  node,
227  (cct_metric_data_t){.i = incr});
228  }
229 }
230 
231 
void hpcrun_mpi_inc(cct_node_t *node, int incr)
Definition: mpi.c:220
cct_node_t * node
Definition: cct.c:128
static void METHOD_FN(init)
Definition: mpi.c:93
static int hpmpi_metric_id
Definition: mpi.c:86
static void cct_metric_data_increment(int metric_id, cct_node_t *x, cct_metric_data_t incr)
Definition: cct2metrics.h:86
int lush_metrics
Definition: main.c:188
#define TD_GET(field)
Definition: thread_data.h:256
bool hpcrun_ev_is(const char *candidate, const char *event_name)
Definition: tokenize.c:194
#define TMSG(f,...)
Definition: messages.h:93
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
#define NULL
Definition: ElfHelper.cpp:85
Definition: cct.c:96
int hpcrun_new_metric(void)
Definition: metrics.c:333
metric_desc_t * hpcrun_set_metric_info(int metric_id, const char *name)
Definition: metrics.c:423
int hpcrun_mpi_metric_id()
Definition: mpi.c:212