📄 dnaml_mon.c
字号:
/* dnaml_mon.c */#define MAIN#include <sys/types.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <stdio.h>#include <string.h>#include <sys/times.h>#include <time.h>#include <math.h>#include "fastDNAml_types.h"#include "fastDNAml_funcs.h"#include "fastDNAml_globals.h"#define SIGINT 2void make_filename(char *, char *, char *, char *, int);double dwalltime00(void);void record_times(stat_data *sp);/* Global variables */#define MAXPROCS 1024int myprogtype = DNAML_MONITOR;FILE *fp, *outfp, *seqfp;void *p;stat_data xstat;proc_data proc[MAXPROCS];/******************************************************************************/int main(int argc, char *argv[]) { /* main */ int type, from, sz, nextsp; char filename[2048] = ""; int xtid; int bufid; int errno; char c, *bp; char buf[2048]; double step_time; double ustime; double twc; boolean firstdone=TRUE; boolean done; int dnaml_ln, dnaml_cur; int ntasks; stat_data *sd;/* Initialize communication runtime library. */ process_init(argc,argv,&myproc);/* Resolve working directory path. Quit if there is an error. */ if( realpath(workdir,buf) == NULL ) { fprintf(stderr,"%s: Bad path name: %s\n",argv[0],workdir); bail(argv[0],99); } strcpy(workdir,buf); strcat(workdir,"/");# ifdef DEBUG make_filename(filename,workdir,run_id,".dnaml_mon.dbg",myproc.tid); if ((dbgfp = fopen(filename,"w")) == NULL) { bail(argv[0],ERR_DEBUGFILE); }# endif make_filename(filename,workdir,run_id,".log",0); if((outfp = freopen(filename,"w",stdout)) == NULL) { bail(argv[0],ERR_LOGFILE); } fprintf(outfp, "Number of workers requested = %d\n", nworkers); nworkers = ntasks = 0; dnaml_ln = dnaml_cur = 1;/*------------------------------------------------------------------------------ * Now we enter a loop looking for messages from any process. */ done = FALSE; while(!done) { from = ANY_SOURCE; type = ANY_TAG; probe_msg(&from,&type); switch(type) { case DNAML_INPUT_TIME: if(infol>0) { recv_msg(&xstat,1,from,type); step_time = xstat.t1 - xstat.t0; twc = xstat.t1 - xstat.tstart; fprintf(outfp, "file input : %8.3f %11.3f sec\n", step_time, twc); fflush(outfp); fprintf(stderr, "file input done at %6.3f sec\n", step_time); if(infol>2) { fprintf(stderr, " 1\n 2\n 3 (%5d) ", DNAML_CHAR_COUNT*(dnaml_ln-1)); } } nextsp = 4; break; case DNAML_TASK_ADDED: recv_msg(&proc[ntasks],1,from,type); if(proc[ntasks].progtype == DNAML_MASTER) { if(dnaml_cur>1) fprintf(stderr,"\n"); fprintf(stderr,"+m %8.8x:%.32s\n",from,proc[ntasks].hostname); fprintf(outfp, "+m %8.8x:%.32s\n",from,proc[ntasks].hostname); dnaml_ln++; dnaml_cur = 1; } else if(proc[ntasks].progtype == DNAML_FOREMAN) { if(dnaml_cur>1) fprintf(stderr,"\n"); fprintf(stderr,"+f %8.8x:%.32s\n",from,proc[ntasks].hostname); fprintf(outfp, "+f %8.8x:%.32s\n",from,proc[ntasks].hostname); dnaml_ln++; dnaml_cur = 1; } else if(proc[ntasks].progtype == DNAML_WORKER) { nworkers++; if(dnaml_cur>1) fprintf(stderr,"\n"); fprintf(stderr,"+w %8.8x:%.32s Total workers=%5d\n", from,proc[ntasks].hostname,nworkers); fprintf(outfp, "+w %8.8x:%.32s Total workers=%5d\n", from,proc[ntasks].hostname,nworkers); dnaml_ln++; dnaml_cur = 1; } ntasks++; break; case DNAML_ADD_SPECS: recv_msg(&c,1,from,type); dnaml_ln = dnaml_cur = 1; fprintf(stderr, "\n%4d (%5d) ", nextsp++, DNAML_CHAR_COUNT*(dnaml_ln-1)); break; case DNAML_SEND_TREE: recv_msg(&c,1,from,type); fputc('+', stderr); dnaml_cur++; break; case DNAML_RECV_TREE: recv_msg(&c,1,from,type); fputc('-', stderr); dnaml_cur++; break; case DNAML_STEP_TIME: recv_msg(&xstat,1,from,type); step_time = xstat.t1 - xstat.t0; twc = xstat.t1 - xstat.tstart; fprintf(outfp, "~%4d Specs: %8.3f %11.3f sec\n", nextsp-1,step_time,twc); fflush(outfp); fprintf(stderr, "\n%4d Step time = %8.3f ", nextsp-1,step_time); fprintf(stderr, "#### Total time = %11.3f seconds", twc); break; /* The following are used in cmon, but not currently in dnaml_mon. */ case DNAML_WORKER_READY: case DNAML_AWOL: recv_msg(&xtid,1,from,type); break; case DNAML_DONE: recv_msg(&xstat,1,from,type); if(firstdone) { fprintf(stderr,"\n"); firstdone=FALSE; } ustime = xstat.utime + xstat.stime; twc = xstat.t1 - xstat.tstart; fprintf(stderr,"-%8.8x: u=%10.2f s=%10.2f u+s=%10.2f wallclock=%10.2f\n", from, xstat.utime, xstat.stime, ustime, twc); fprintf(outfp, "-%8.8x: u=%10.2f s=%10.2f u+s=%10.2f wallclock=%10.2f\n", from, xstat.utime, xstat.stime, ustime, twc); nworkers--; if(nworkers+3 == 1) { done = TRUE; } break; } if (dnaml_cur % (DNAML_CHAR_COUNT + 1) == 0) { dnaml_ln++; dnaml_cur = 1; fprintf(stderr, "\n (%5d) ", DNAML_CHAR_COUNT * (dnaml_ln-1)); } }/*------------------------------------------------------------------------------ * Write out performance statistics for my process. */ sd = &myproc.stats; record_times(sd); ustime = sd->utime + sd->stime; twc = sd->t1 - sd->tstart; fprintf(stderr,"-%8.8x: u=%10.2f s=%10.2f u+s=%10.2f wallclock=%10.2f\n", myproc.tid, sd->utime, sd->stime, ustime, twc); fprintf(outfp, "-%8.8x: u=%10.2f s=%10.2f u+s=%10.2f wallclock=%10.2f\n", myproc.tid, sd->utime, sd->stime, ustime, twc); fclose(outfp); bail((char*)NULL,0); } /* main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -