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
|
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: Progress_bar
*
* %I
* Written by: Emmanuel Farhi
* Date: 2002
* Origin: ILL
*
* A simulation progress bar
*
* %D
* 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)
*
* %P
* 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 if set to "", it is set to the name of the instrument.
*
* %E
*******************************************************************************/
DEFINE COMPONENT Progress_bar
DEFINITION PARAMETERS ()
SETTING PARAMETERS (string profile="NULL", percent=10,flag_save=0,minutes=0)
OUTPUT PARAMETERS (IntermediateCnts,StartTime,EndTime,CurrentTime)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,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;
%}
INITIALIZE
%{
IntermediateCnts=0;
StartTime=0;
EndTime=0;
CurrentTime=0;
fprintf(stdout, "[%s] Initialize\n", mcinstrument_name);
if (percent*mcget_ncount()/100 < 1e5) {
percent=1e5*100.0/mcget_ncount();
}
%}
TRACE
%{
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;
fprintf(stdout, "\nTrace ETA ");
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);
} 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)) )
{
fprintf(stdout, "%d ", (int)(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) mcsave(NULL);
}
%}
SAVE
%{
MPI_MASTER(fprintf(stdout, "\nSave [%s]\n", mcinstrument_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, mcinstrument_name);
else strcpy(filename, profile);
DETECTOR_OUT_1D(
"Intensity profiler",
"Component index [1]",
"Intensity",
"prof", 1, mcNUMCOMP, mcNUMCOMP-1,
&mcNCounter[1],&mcPCounter[1],&mcP2Counter[1],
filename);
}
%}
FINALLY
%{
time_t NowTime;
time(&NowTime);
fprintf(stdout, "\nFinally [%s: %s]. Time: ", mcinstrument_name, mcdirname ? mcdirname : ".");
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)/3660.0);
else
fprintf(stdout, "%g [min] ", difftime(NowTime,StartTime)/60.0);
fprintf(stdout, "\n");
%}
MCDISPLAY
%{
%}
END
|