Commit 155a319e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added counter

parent 7f1a9b52
......@@ -430,6 +430,7 @@ src/color.c -text
src/color.h -text
src/commandline.c -text
src/config.h.in -text
src/counter.h -text
src/dmemory.h -text
src/dtypes.h -text
src/ecacore.c -text
......
......@@ -24,12 +24,14 @@
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "counter.h"
int streamID = 0;
int vlistID = 0;
int varID = 0;
int levelID = 0;
int tsID = 0;
int tsID1 = 0;
int tsID2 = 59;
double *array = NULL;
#define MAX_LINE 256
......@@ -133,31 +135,41 @@ int com_quit(char *arg)
int com_stat(char *arg)
{
int nrecs;
int tsID;
nrecs = streamInqTimestep(streamID, tsID);
if ( nrecs == 0 )
for ( tsID = tsID1; tsID <= tsID2; ++tsID )
{
fprintf(stderr, "Timestep %d out of range!\n", tsID);
}
else
{
int i;
int nmiss;
int gridsize;
double fmin = 1.e50 , fmax = -1.e50, fmean = 0;
streamReadVarSlice(streamID, varID, levelID, array, &nmiss);
gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
for ( i = 0; i < gridsize; ++i )
nrecs = streamInqTimestep(streamID, tsID);
if ( nrecs == 0 )
{
if ( array[i] < fmin ) fmin = array[i];
if ( array[i] > fmax ) fmax = array[i];
fmean += array[i];
fprintf(stderr, "Timestep %d out of range!\n", tsID+1);
break;
}
else
{
int i;
int nmiss;
int gridsize;
double fmin = 1.e50 , fmax = -1.e50, fmean = 0;
counter_t counter;
counter_start(&counter);
streamReadVarSlice(streamID, varID, levelID, array, &nmiss);
gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
for ( i = 0; i < gridsize; ++i )
{
if ( array[i] < fmin ) fmin = array[i];
if ( array[i] > fmax ) fmax = array[i];
fmean += array[i];
}
fmean /= gridsize;
counter_stop(&counter);
fprintf(stdout, "%d %d %d %g %g %g (%gs)\n",
tsID+1, varID+1, levelID+1, fmin, fmean, fmax,
counter_cputime(counter));
}
fmean /= gridsize;
fprintf(stdout, "%g %g %g\n", fmin, fmean, fmax);
}
return (0);
}
......@@ -258,7 +270,7 @@ void *Command(void *argument)
{
static char func[] = "Command";
int nrecs;
int tsID, recID, varID, levelID;
int recID, varID, levelID;
int gridsize;
int nmiss;
int taxisID;
......@@ -311,19 +323,6 @@ void *Command(void *argument)
}
}
*/
/*
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID, &varID, &levelID);
streamReadRecord(streamID, array, &nmiss);
}
tsID++;
}
*/
streamClose(streamID);
......
......@@ -164,6 +164,7 @@ cdo_SOURCES = Arith.c \
cdo.c \
cdo_pthread.c \
cdo_vlist.c \
counter.h \
field.c \
fieldc.c \
field2.c \
......
......@@ -440,6 +440,7 @@ cdo_SOURCES = Arith.c \
cdo.c \
cdo_pthread.c \
cdo_vlist.c \
counter.h \
field.c \
fieldc.c \
field2.c \
......
#ifndef _COUNTER_H
#define _COUNTER_H
typedef struct {
double cputime;
char mark[32];
}
counter_t;
void counter_start(counter_t *counter);
void counter_stop(counter_t *counter);
double counter_cputime(counter_t counter);
#endif /* _COUNTER_H */
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2008 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Copyright (C) 2003-2010 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
......@@ -72,17 +72,17 @@ void util_read_real_time(void *it);
void util_diff_real_time(void *it1, void *it2, double *t);
static FILE *rt_unit;
FILE *rt_unit = NULL;
enum {rt_stat_undef, rt_stat_on, rt_stat_off};
/* minimal internal time needed to do one measuremenet */
/* minimal internal time needed to do one measurement */
static double tm_shift = 0.0;
double tm_shift = 0.0;
/* average total overhead for one timer_start & timer_stop pair */
static double tm_overhead = 0.0;
double tm_overhead = 0.0;
#define MAX_TIMER 128 /* max number of timers allowed */
......@@ -101,17 +101,19 @@ typedef struct {
}
RT_TYPE;
static RT_TYPE rt[MAX_TIMER];
static RT_TYPE rt_init = {0, 0, 0, 0, 1.e30, 0, 0, "", "noname"};
static int timer_need_init = 1;
static int top_timer = 0;
RT_TYPE rt[MAX_TIMER];
RT_TYPE rt_init = {0, 0, 0, 0, 1.e30, 0, 0, "", "noname"};
int timer_need_init = 1;
int top_timer = 0;
static void set_time_mark(void *mark)
static
void set_time_mark(void *mark)
{
util_read_real_time(mark);
}
static double get_time_val(void *mark0)
static
double get_time_val(void *mark0)
{
double dt;
char mark[32];
......@@ -124,9 +126,10 @@ static double get_time_val(void *mark0)
return (dt);
}
static int ntests = 100; /* tests need about n microsecs on pwr4 */
int ntests = 100; /* tests need about n microsecs on pwr4 */
static double m1(void)
static
double m1(void)
{
double dt, dt0;
int i;
......@@ -143,7 +146,8 @@ static double m1(void)
return (dt0);
}
static double m2(void)
static
double m2(void)
{
char mark1[32], mark2[32];
double dt1, dt2, dt0;
......@@ -163,14 +167,16 @@ static double m2(void)
return (dt0);
}
static void estimate_overhead(void)
static
void estimate_overhead(void)
{
tm_shift = m1();
tm_overhead = m2();
}
static void timer_init(void)
static
void timer_init(void)
{
rt_unit = stderr;
......@@ -207,14 +213,14 @@ int timer_new(char *text)
return (it);
}
static
void timer_check(int it)
{
if ( it < 0 || it > (top_timer-1) )
fprintf(rt_unit, "timer: invalid timer id %d\n", it);
}
static
double timer_val(int it)
{
double val, dt;
......@@ -232,7 +238,7 @@ double timer_val(int it)
return (val);
}
static
void timer_header(void)
{
fprintf(rt_unit, "\nTimer report: shift = %g\n", tm_shift);
......@@ -300,3 +306,35 @@ void timer_stop(int it)
rt[it].stat = rt_stat_off;
}
#include "counter.h"
static
void counter_init(counter_t *counter)
{
counter->cputime = 0;
}
void counter_start(counter_t *counter)
{
counter_init(counter);
if ( timer_need_init ) timer_init();
set_time_mark(counter->mark);
}
void counter_stop(counter_t *counter)
{
counter->cputime = get_time_val(counter->mark);
}
double counter_cputime(counter_t counter)
{
return (counter.cputime);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment