(UP)

Another simple, yet useful procedure that Viktor is using in his main code. Simulation runs sometimes can take weeks. Often it is crucial to know how far the code has ran and despite all the benchmarking of the code (which allow to extrapolate the time left) it is not always correct, as many other processes might have been running on the same node. The following procedure dumps information (about how many steps are accomplished, PID of the main code, actual time running since start, etc) in the file 'name_time'.
(sample-out)

#include <stdio.h>
#include <string.h>
#include <math.h> /*to compile-> .... -lm */
#include <malloc.h>
#include <sys/types.h>
#include <unistd.h>
/*use all the libraries you need*/


void main(void)
{

pid_t getpid(void);
int currPID;
void timeremaining(int eq,char name[20]);
int eq;
char name[20];/*name for output files*/

currPID=getpid();

/* initialization lines*/


for (eq=0;eq<=100000000;eq++)
{

/*lines with extensive calculations. Very long.....*/
timeremaining(int eq,char name[20]);

}


void timeremaining(int eq,char name[20])
{
char strxTime[50];
FILE *fpTime;
float persrt;
int a,b;

sprintf(strxTime,"%s_time",name);
fpTime=fopen(strxTime,"w");
b=(eq*100)/BIGnumb;
persrt=(float)(eq)/(float)(BIGnumb);

/*187,137*/
fprintf(fpTime,"Process running PID: %d\n",currPID);
fprintf(fpTime,"seps accomplished : %d\n",eq);
fprintf(fpTime,"Time running = %f of total\n",persrt);
fprintf(fpTime,"Time remaining = %f of total\n\n",(1-persrt));
fprintf(fpTime,"+----+----+----+----+----+----+----+----+----+----+\n");
fprintf(fpTime,"| 10 20 30 40 50 60 70 80 90 |\n");
fprintf(fpTime,"+----+----+----+----+----+----+----+----+----+----+\n");
fprintf(fpTime,"|");
for(a=1;a<99;a=a+2)
{
if(b>=a)
{
fprintf(fpTime,"%c",187);
}
else
{
fprintf(fpTime," ");
}
}
fprintf(fpTime,"|\n");
fprintf(fpTime,"+----+----+----+----+----+----+----+----+----+----+\n\n");
fprintf(fpTime,"Information from TOP :\n");
fclose(fpTime);
sprintf(strxTime,"ps -u $USER | grep 'TIME' >> %s_time",name);
system(strxTime);
sprintf(strxTime,"ps -u $USER | grep '%d' >> %s_time",currPID,name);
system(strxTime);


}/* end of void timeremaining(void)*/

/*(c)2000 Viktor Yarmolenko, viktor.yarmolenko@physics.org*/




(UP)








  Science
Programming
Other Activities






©2002-2004 Viktor Yarmolenko