/[escript]/trunk/escript/src/blocktimer.c
ViewVC logotype

Contents of /trunk/escript/src/blocktimer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1628 - (show annotations)
Fri Jul 11 13:12:46 2008 UTC (11 years, 4 months ago) by phornby
File MIME type: text/plain
File size: 3917 byte(s)

Merge in /branches/windows_from_1456_trunk_1620_merged_in branch.

You will find a preserved pre-merge trunk in tags under tags/trunk_at_1625.
That will be useful for diffing & checking on my stupidity.

Here is a list of the conflicts and their resolution at this
point in time.


=================================================================================
(LLWS == looks like white space).

finley/src/Assemble_addToSystemMatrix.c - resolve to branch - unused var. may be wrong.....
finley/src/CPPAdapter/SystemMatrixAdapter.cpp - resolve to branch - LLWS
finley/src/CPPAdapter/MeshAdapter.cpp - resolve to branch - LLWS
paso/src/PCG.c - resolve to branch - unused var fixes.
paso/src/SolverFCT.c - resolve to branch - LLWS
paso/src/FGMRES.c - resolve to branch - LLWS
paso/src/Common.h - resolve to trunk version. It's omp.h's include... not sure it's needed,
but for the sake of saftey.....
paso/src/Functions.c - resolve to branch version, indentation/tab removal and return error
on bad unimplemented Paso_FunctionCall.
paso/src/SolverFCT_solve.c - resolve to branch version, unused vars
paso/src/SparseMatrix_MatrixVector.c - resolve to branch version, unused vars.
escript/src/Utils.cpp - resloved to branch, needs WinSock2.h
escript/src/DataExpanded.cpp - resolved to branch version - LLWS
escript/src/DataFactory.cpp - resolve to branch version
=================================================================================

This currently passes tests on linux (debian), but is not checked on windows or Altix yet.

This checkin is to make a trunk I can check out for windows to do tests on it.

Known outstanding problem is in the operator=() method of exceptions
causing warning messages on the intel compilers.

May the God of doughnuts have mercy on my soul.


1
2 /* TODO: note if has been initialized, give error only once if not */
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <time.h>
8 #include <search.h>
9 #ifdef _OPENMP
10 #include <omp.h>
11 #endif
12
13 #include "escript/blocktimer.h"
14 #include "malloc.h"
15 #include "string.h"
16
17 #ifdef PASO_MPI
18 #include "mpi.h"
19 #endif
20
21 #ifdef BLOCKTIMER
22 static char *g_names[NUM_TIMERS]; /* Names of the timers */
23 static int g_count[NUM_TIMERS]; /* How many times was the timer incremented? */
24 static double g_times[NUM_TIMERS]; /* The total time spent in the block */
25 static double g_start_time; /* Start time for the entire program */
26 static int g_initialized = 0; /* Has the blocktimer been initialized? */
27 static int g_end_computed = 0; /* Has the end time been set? */
28 #endif /* BLOCKTIMER */
29
30 void
31 blocktimer_initialize()
32 {
33 #ifdef BLOCKTIMER
34 int i;
35
36 for (i=0; i<NUM_TIMERS; i++) {
37 g_names[i] = (char *)NULL;
38 g_times[i] = 0.0;
39 g_count[i] = 0;
40 }
41
42 if (hcreate(NUM_TIMERS) == 0) {
43 perror("hcreate");
44 fprintf(stderr, "blocktimer_initialize: Could not initialize hash table\n");
45 exit(1);
46 }
47
48 g_initialized = 1;
49
50 g_start_time = blocktimer_time();
51
52 /* Initialize timer for "entire program" to zero so it appears first in the report */
53 blocktimer_increment("entire program", g_start_time);
54 g_count[0] = 0; /* Reset counter for "entire program" to zero */
55 #endif /* BLOCKTIMER */
56 }
57
58 void
59 blocktimer_increment(char *name, double start_time)
60 {
61 #ifdef BLOCKTIMER
62 int id;
63
64 if (!g_initialized) { return; }
65
66 id = blocktimer_getOrCreateTimerId(name);
67
68 g_times[id] += blocktimer_time() - start_time;
69 g_count[id] += 1;
70 #endif /* BLOCKTIMER */
71 }
72
73 int
74 blocktimer_getOrCreateTimerId(char *name)
75 {
76 int id=0;
77 #ifdef BLOCKTIMER
78 static int nextId = 0; /* Next timer ID to assign */
79 ENTRY item, *found_item;
80
81 if (!g_initialized) { return(0); }
82
83 /* Has a timer with 'name' already been defined? */
84 item.key = name;
85 item.data = (void *) NULL;
86 found_item = hsearch(item, FIND);
87
88 if (found_item != NULL) { /* Already defined so retrieve it from the hash */
89 /* Return the ID of the entry we found */
90 int *idTmp = found_item->data;
91 id = *idTmp;
92 }
93 else { /* Not already defined so create one */
94 /* malloc new int, can't use stack var or all items share same data */
95 int *idTmp = (int *)malloc(sizeof(int));
96 /* Enter the new name in the hash */
97 if (nextId >= NUM_TIMERS) {
98 fprintf(stderr, "blocktimer: exceeded limit of %d timers, increase NUM_TIMERS\n", NUM_TIMERS);
99 exit(1);
100 }
101 *idTmp = nextId++;
102 item.key = name;
103 item.data = (void *) idTmp;
104 hsearch(item, ENTER);
105 id = *idTmp;
106 g_names[id] = (char *)strdup(name);
107 }
108
109 #endif /* BLOCKTIMER */
110 return(id);
111 }
112
113 void
114 blocktimer_reportSortByName()
115 {
116 #ifdef BLOCKTIMER
117 int i;
118
119 if (!g_initialized) { return; }
120
121 if (!g_end_computed) {
122 blocktimer_increment("entire program", g_start_time);
123 g_end_computed = 1;
124 }
125 printf("BlockTimer sorted by name (sorting TBD):\n");
126 for(i=0; i<NUM_TIMERS; i++) {
127 if (g_names[i] != (char *) NULL) {
128 printf(" %7d %15.2lf %s\n", g_count[i], g_times[i], g_names[i]);
129 }
130 }
131 #endif /* BLOCKTIMER */
132 }
133
134 void
135 blocktimer_reportSortByTime()
136 {
137 #ifdef BLOCKTIMER
138 int i;
139
140 if (!g_initialized) { return; }
141
142 if (!g_end_computed) {
143 blocktimer_increment("entire program", g_start_time);
144 g_end_computed = 1;
145 }
146 printf("BlockTimer sorted by time (sorting TBD):\n");
147 for(i=0; i<NUM_TIMERS; i++) {
148 if (g_names[i] != (char *) NULL) {
149 printf(" %7d %15.2lf seconds for %s\n", g_count[i], g_times[i], g_names[i]);
150 }
151 }
152 #endif /* BLOCKTIMER */
153 }
154
155 /* Copied from Paso_timer() */
156 double
157 blocktimer_time()
158 {
159 double out=0.0;
160 #ifdef PASO_MPI
161 out = MPI_Wtime();
162 #else
163 #ifdef _OPENMP
164 out=omp_get_wtime();
165 #else
166 out=((double) clock())/CLOCKS_PER_SEC;
167 #endif
168 #endif
169 return(out);
170 }
171

  ViewVC Help
Powered by ViewVC 1.1.26