Search

link to homepage

Institute for Advanced Simulation (IAS)

Navigation and service


General usage of jutime

Compiling and linking with jutime

jutime is a static library and has interfaces for C and Fortran90. To use the library you need to include the corresponding header file/module in your application.

C#include <jutimer.h>
Fortran90use jutimer

For the compilation and linking step the C or the Fortran library of jutime has to be used.

C-L$JUTIME_LIB -I$JUTIME_INC -ljutimer_c
Fortran90-L$JUTIME_LIB -I$JUTIME_INC -ljutimer_f

where JUTIME_LIB is the absolute path to the directory with the jutime libraries and JUTIME_INC contains the absolute path to the jutime include files.

Example for using jutime

We will explain the general usage of jutime in the following for an application written in C. Please see the API of jutime for further information about the available routines. In order to measure the time an application spends in a certain part of the code, you first need to create a timer instance in jutime.

if (my_rank == 0){
instance1 =
jutimer_inst_init_c(&my_rank,"Rank 0",&verbosity);
}

This will create a timer instance with the name "Rank 0" and the tag instance1. This is useful, for example, if you are running a parallel application and you would like to measure the same events on different MPI tasks. In this case you can create timer instances on different MPI tasks and define the same timers inside each instance.

In jutime, time is measured via timers. For different events, different timers can be created within a time instance. For example, if you have a code which reads in data, then does some calculations in one (or more) loops on the data and finally writes the results back to disk, you might want to measure the time the code spends in I/O and in the loop(s). For this purpose you can create two timers, one I/O time and one loop timer.

if (my_rank == 0){
timer_total_time =
jutimer_create_c(&instance1,
"Total time",&measure,&verbosity);
timer_io =
jutimer_create_c(&instance1,
"I/O time",&measure,&verbosity);
timer_loops =
jutimer_create_c(&instance1,
"loop time",&measure,&verbosity);
}

To start measuring time, the corresponding timer needs to be started. If the measurement is finished (e.g. at the end of a loop), the timer can be stopped. Each timer can be started and stopped as many times as needed. The total time a timer measures will be summed up.

jutimer_start_c(&instance1,&timer_loops,&verbosity);
for (i=0;i<100000;i++){
f = f + sqrt((float) i);
for (j=0;j<1000;j++){
f = f - sqrt((float) j);
}
}
jutimer_stop_c(&instance1,&timer_loopa,&verbosity);
jutimer_start_c(&instance1,&timer_io,&verbosity);
// Doing some I/O here
// ...
// Finished with I/O
jutimer_stop_c(&instance1,&timer_io,&verbosity);
jutimer_start_c(&instance1,&timer_loops,&verbosity);
//
for (i=0;i<100000;i++){
f = f + sqrt((float) i);
for (j=0;j<1000;j++){
f = f - sqrt((float) j);
}
}
jutimer_stop_c(&instance1,&timer_loops,&verbosity);

The elapsed time measured by a timer can be queried at any time, regardless whether the timer is still running or stopped.

jutimer_return_value_c(&instance1,&timer_total_time,
&timer_value,&verbosity);
printf ("Current value of timer for total time:
%10.2f\n", timer_value);

Finally, a timing statistics can be printed (see the API description for the different possibilities).

jutimer_print_all_c(&instance1,&timer_total_time,
&verbosity_print);


Servicemeu

Helmholtz-Gemeinschaft

Homepage