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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 11 months ago) by ksteube
File MIME type: text/plain
File size: 8189 byte(s)
Copyright updated in all files

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

  ViewVC Help
Powered by ViewVC 1.1.26