1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*******************************************************************************
*
* McXtrace, x-ray tracing package
* Copyright, All rights reserved
* DTU Physics, Kgs. Lyngby, Denmark
* Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: Progress_bar
*
* %Identification
* Written by: Emmanuel Farhi
* Modified by: Erik Knudsen
* Date: 2009
* Origin: ILL
* Release: McXtrace 1.0
*
* A simulation progress bar
*
* %Description
* An indicator of the progress of the simulation, monitoring
* the Init, Trace with the achieved percentage, and the Finally section.
* Intermediate savings (e.g. triggered by USR2 signal) are also shown.
* This component should be positioned at the very begining of the instrument
* The profile option will save the intensity and number of events for each
* component It may be used to evaluate the simulation efficiency.
*
* Example: Progress_bar(percent=10,flag_save=1) AT (0,0,0)
*
* %Parameters
* INPUT PARAMETERS:
* percent: [0-100] percentage interval between updates. Default is 10%.
* minutes: [min] time in minutes between updates (Overrides percent flag).
* flag_save: [0|1] flag to enable intermediate saving for all monitors
* profile: [str] file name to save the simulation profile in. If set to "", it is set to the name of the instrument.
*
* %End
*******************************************************************************/
DEFINE COMPONENT Progress_bar
SETTING PARAMETERS (string profile="NULL", percent=10,flag_save=0,minutes=0)
/* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */
DECLARE
%{
#ifndef PROGRESS_BAR
#define PROGRESS_BAR
#else
#error Only one Progress_bar component may be used in an instrument definition.
#endif
double IntermediateCnts;
time_t StartTime;
time_t EndTime;
time_t CurrentTime;
char infostring[64];
%}
INITIALIZE
%{
IntermediateCnts=0;
StartTime=0;
EndTime=0;
CurrentTime=0;
fprintf(stdout, "[%s] Initialize\n", instrument_name);
if (percent*mcget_ncount()/100 < 1e5) {
percent=1e5*100.0/mcget_ncount();
}
#ifdef OPENACC
time(&StartTime);
#endif
#ifdef USE_MPI
sprintf(infostring, "(%i MPI processes) ", mpi_node_count);
#else
sprintf(infostring, "");
#endif
%}
TRACE
%{
#ifndef OPENACC
double ncount;
ncount = mcget_run_num();
if (!StartTime) {
time(&StartTime); /* compute starting time */
IntermediateCnts = 1e3;
}
time_t NowTime;
time(&NowTime);
/* compute initial estimate of computation duration */
if (!EndTime && ncount >= IntermediateCnts) {
CurrentTime = NowTime;
if (difftime(NowTime,StartTime) > 10 && ncount) { /* wait 10 sec before writing ETA */
EndTime = StartTime + (time_t)(difftime(NowTime,StartTime)
*(double)mcget_ncount()/ncount);
IntermediateCnts = 0;
MPI_MASTER(
fprintf(stdout, "\nTrace ETA ");
fprintf(stdout, "%s", infostring);
if (difftime(EndTime,StartTime) < 60.0)
fprintf(stdout, "%g [s] %% ", difftime(EndTime,StartTime));
else if (difftime(EndTime,StartTime) > 3600.0)
fprintf(stdout, "%g [h] %% ", difftime(EndTime,StartTime)/3600.0);
else
fprintf(stdout, "%g [min] ", difftime(EndTime,StartTime)/60.0);
fprintf(stdout, "\n");
);
} else IntermediateCnts += 1e3;
fflush(stdout);
}
/* display percentage when percent or minutes have reached step */
if (EndTime && mcget_ncount() &&
( (minutes && difftime(NowTime,CurrentTime) > minutes*60)
|| (percent && !minutes && ncount >= IntermediateCnts)) )
{
MPI_MASTER(
fprintf(stdout, "%llu %%\n", (unsigned long long)(ncount*100.0/mcget_ncount())); fflush(stdout);
);
CurrentTime = NowTime;
IntermediateCnts = ncount + percent*mcget_ncount()/100;
/* check that next intermediate ncount check is a multiple of the desired percentage */
IntermediateCnts = floor(IntermediateCnts*100/percent/mcget_ncount())*percent*mcget_ncount()/100;
/* raise flag to indicate that we did something */
SCATTER;
if (flag_save) save(NULL);
}
#endif
%}
SAVE
%{
MPI_MASTER(fprintf(stdout, "\nSave [%s]\n", instrument_name););
if (profile && strlen(profile) && strcmp(profile,"NULL") && strcmp(profile,"0")) {
char filename[256];
if (!strlen(profile) || !strcmp(profile,"NULL") || !strcmp(profile,"0")) strcpy(filename, instrument_name);
else strcpy(filename, profile);
DETECTOR_OUT_1D(
"Intensity profiler",
"Component index [1]",
"Intensity",
"prof", 1, mcNUMCOMP, mcNUMCOMP-1,
&(instrument->counter_N[1]),&(instrument->counter_P[1]),&(instrument->counter_P2[1]),
filename);
}
%}
FINALLY
%{
time_t NowTime;
time(&NowTime);
fprintf(stdout, "\nFinally [%s: %s]. Time: ", instrument_name, dirname ? dirname : ".");
if (difftime(NowTime,StartTime) < 60.0)
fprintf(stdout, "%g [s] ", difftime(NowTime,StartTime));
else if (difftime(NowTime,StartTime) > 3600.0)
fprintf(stdout, "%g [h] ", difftime(NowTime,StartTime)/3600.0);
else
fprintf(stdout, "%g [min] ", difftime(NowTime,StartTime)/60.0);
fprintf(stdout, "\n");
%}
MCDISPLAY
%{
%}
END
|