/[escript]/trunk/paso/src/performance.c
ViewVC logotype

Contents of /trunk/paso/src/performance.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (show annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 7 months ago) by trankine
File MIME type: text/plain
File size: 8245 byte(s)
And get the *(&(*&(* name right
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Paso: perfomance monitor interface using papi */
19
20 /**************************************************************/
21
22 /* Copyrights by ACcESS Australia 2006 */
23 /* Author: gross@access.edu.au */
24
25 /**************************************************************/
26
27 #include "Paso.h"
28 #include "performance.h"
29
30 /* */
31 /* sets up the the monitoring process */
32 /* */
33 void Performance_open(Paso_Performance* pp,int verbose) {
34 #ifdef PAPI
35 int i,j;
36 #pragma omp master
37 {
38 pp->event_set=PAPI_NULL;
39 /* Initialize the PAPI library */
40 int retval = PAPI_library_init(PAPI_VER_CURRENT);
41 if (retval != PAPI_VER_CURRENT && retval > 0) {
42 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI library version mismatch.");
43 } else if (retval < 0) {
44 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI initialization error.");
45 } else {
46 if (PAPI_create_eventset(&(pp->event_set)) != PAPI_OK)
47 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI event set set up failed.");
48 }
49 if (Paso_noError()) {
50 /* try to add various monitors */
51 pp->num_events=0;
52 if (PAPI_add_event(pp->event_set, PAPI_FP_OPS) == PAPI_OK) {
53 pp->events[pp->num_events]=PAPI_FP_OPS;
54 pp->num_events++;
55 }
56 if (PAPI_add_event(pp->event_set, PAPI_L1_DCM) == PAPI_OK) {
57 pp->events[pp->num_events]=PAPI_L1_DCM;
58 pp->num_events++;
59 }
60 if (PAPI_add_event(pp->event_set, PAPI_L2_DCM) == PAPI_OK) {
61 pp->events[pp->num_events]=PAPI_L2_DCM;
62 pp->num_events++;
63 }
64 if (PAPI_add_event(pp->event_set, PAPI_L3_DCM) == PAPI_OK) {
65 pp->events[pp->num_events]=PAPI_L3_DCM;
66 pp->num_events++;
67 }
68 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
69 pp->cycles[i]=0;
70 pp->set[i]=PERFORMANCE_UNUSED;
71 for (j=0;j<PERFORMANCE_NUM_EVENTS;++j) pp->values[i][j]=0.;
72 }
73 PAPI_start(pp->event_set);
74 }
75 }
76 #endif
77 }
78 /* find the index of an event in the list of monitored events */
79 int Performance_getEventIndex(Paso_Performance* pp, int event_id) {
80 #ifdef PAPI
81 int i;
82 for (i=0;i<pp->num_events;++i)
83 if (pp->events[i]==event_id) return i;
84 #endif
85 return PERFORMANCE_UNMONITORED_EVENT;
86 }
87 /* */
88 /* shuts down the monitoring process */
89 /* */
90 void Performance_close(Paso_Performance* pp,int verbose) {
91 #ifdef PAPI
92 long_long values[PERFORMANCE_NUM_EVENTS];
93 #pragma omp master
94 {
95 if (Paso_noError() && verbose) {
96 int i;
97 int i_ops=Performance_getEventIndex(pp,PAPI_FP_OPS);
98 int i_l1_miss=Performance_getEventIndex(pp,PAPI_L1_DCM);
99 int i_l2_miss=Performance_getEventIndex(pp,PAPI_L2_DCM);
100 int i_l3_miss=Performance_getEventIndex(pp,PAPI_L3_DCM);
101 printf(" monitor |");
102 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" flops/cycle |");
103 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L1 miss/flops |");
104 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L2 miss/flops |");
105 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L3 miss/flops |");
106 printf("\n");
107 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
108 if (pp->set[i]!=PERFORMANCE_UNUSED ) {
109 switch(i) {
110 case PERFORMANCE_ALL:
111 printf(" over all |");
112 break;
113 case PERFORMANCE_SOLVER:
114 printf(" solver |");
115 break;
116 case PERFORMANCE_PRECONDITIONER_INIT:
117 printf(" init. preconditioner |");
118 break;
119 case PERFORMANCE_PRECONDITIONER:
120 printf(" preconditioner |");
121 break;
122 case PERFORMANCE_MVM:
123 printf(" matrix-vector product |");
124 break;
125 case PERFORMANCE_ASSEMBLAGE:
126 printf(" assemblage |");
127 break;
128 default:
129 printf(" no name |");
130 break;
131 }
132 if (pp->set[i]==PERFORMANCE_CLOSED ) {
133 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" %12.5e |",(((double)(pp->values[i][i_ops]))/((double)(pp->cycles[i]))));
134 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT)
135 printf(" %13.5e |",(((double)(pp->values[i][i_l1_miss]))/((double)(pp->values[i][i_ops]))));
136 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT)
137 printf(" %13.5e |",(((double)(pp->values[i][i_l2_miss]))/((double)(pp->values[i][i_ops]))));
138 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT)
139 printf(" %13.5e |",(((double)(pp->values[i][i_l3_miss]))/((double)(pp->values[i][i_ops]))));
140 } else {
141 printf("not closed!!!");
142 }
143 printf("\n");
144 }
145 }
146 }
147 PAPI_stop(pp->event_set,values);
148 PAPI_cleanup_eventset(pp->event_set);
149 PAPI_destroy_eventset(&(pp->event_set));
150 }
151 #endif
152 }
153 /* */
154 /* switches on a monitor */
155 /* */
156 void Performance_startMonitor(Paso_Performance* pp,int monitor) {
157 #ifdef PAPI
158 int i;
159 long_long values[PERFORMANCE_NUM_EVENTS];
160 #pragma omp barrier
161 #pragma omp master
162 {
163 /* Start counting events in the Event Set */
164 PAPI_read(pp->event_set,values);
165 for (i=0;i<pp->num_events;++i) pp->values[monitor][i]-=values[i];
166 /* set cycles */
167 pp->cycles[monitor]-=PAPI_get_real_cyc();
168 pp->set[monitor]=PERFORMANCE_OPENED;
169 }
170 #endif
171 }
172 /* */
173 /* switches off a monitor */
174 /* */
175 void Performance_stopMonitor(Paso_Performance* pp,int monitor) {
176 #ifdef PAPI
177 int i;
178 long_long values[PERFORMANCE_NUM_EVENTS];
179 #pragma omp barrier
180 #pragma omp master
181 {
182 /* Add the counters in the Event Set */
183 PAPI_read(pp->event_set,values);
184 for (i=0;i<pp->num_events;++i) pp->values[monitor][i]+=values[i];
185 /* set cycles */
186 pp->cycles[monitor]+=PAPI_get_real_cyc();
187 pp->set[monitor]=PERFORMANCE_CLOSED;
188 }
189 #endif
190 }
191 /*
192 * $Log$
193 */
194

  ViewVC Help
Powered by ViewVC 1.1.26