⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 master.c

📁 fastDNAml is an attempt to solve the same problem as DNAML, but to do so faster and using less memo
💻 C
字号:
#define MAIN#include  <stdlib.h>#include  <stdio.h>#include  <string.h>#include  <sys/types.h>#include  <sys/times.h>#include  <time.h>#include  "fastDNAml_types.h"#include  "fastDNAml_funcs.h"#include  "fastDNAml_globals.h"#ifdef DEBUG#  define LOG_SEQ_DATA_REQUEST(from)\     fprintf(dbgfp,"DNAML_SEQ_DATA_REQUEST from t%8.8x ... ",from);fflush(dbgfp)#  define LOG_SENT_SEQFILE(seq_file)\     fprintf(dbgfp,"sent filename **%s**\n",seq_file);fflush(dbgfp)#  define LOG_SENT_SEQDATA(num) \     fprintf(dbgfp,"sent %d bytes\n",num);fflush(dbgfp)#else#  define LOG_SEQ_DATA_REQUEST(from)#  define LOG_SENT_SEQFILE(seq_file)#  define LOG_SENT_SEQDATA(num)#endifint          myprogtype = DNAML_MASTER;FILE         *outfp = NULL;#define MAXPROCS   1proc_data    proc[MAXPROCS];/*==========================================================================*//*       Main routine for fastDNAml master process.                         *//*==========================================================================*/main (int argc, char *argv[]){ /* DNA Maximum Likelihood */  char          *bp,c;  char          outfn[2048] = "";  char          dbgfn[2048] = "";  char          buf[2048];  char          buf2[2048];  FILE          *seqfp;  analdef       *adef;  rawdata       *rdta;  cruncheddata  *cdta;  tree          *tr;      /*  current tree */  bestlist      *bt;      /*  topology of best found tree */  double        t0,t1;  int           from,xtid,type;  int           j;  process_init(argc,argv,&myproc);  if(monitor_id!=INVALID_ID) {    send_msg(&myproc,1,monitor_id,DNAML_TASK_ADDED);  }/* 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);    end_it_all(0);  }  strcpy(workdir,buf);  strcat(workdir,"/");#if DEBUG  make_filename(dbgfn,workdir,run_id,".master.dbg",myproc.tid);  dbgfp = fopen(dbgfn,"w");#endif/* Reopen stdout as the best tree file */   make_filename(outfn,workdir,run_id,bt_ext,0);  if ((outfp = freopen(outfn,"w",stdout)) == NULL) {     end_it_all(0);  }/* Resolve the sequence data file name. Quit if there is an error.  */  if( seq_file[0] == '/' ) {    strcpy(buf2,seq_file);  }  else {    strcpy(buf2,workdir);    strcat(buf2,seq_file);  }  if( realpath(buf2,buf) == NULL ) {    fprintf(stderr, "%s: bad path - %s\n",argv[0],buf2);    end_it_all(ERR_SEQDATA);  }/* Now open and read the sequence data file. Quit if it cannot be opened. */  if((seqfp=fopen(buf,"r"))==(FILE*)NULL) {    fprintf(stderr, "%s: cannot open sequence data file %s\n",argv[0],buf);    end_it_all(ERR_SEQDATA);  }         else {      fseek(seqfp,0L,SEEK_END);    seq_data_size = (ftell(seqfp)+1);    seq_data_str = (char*)malloc(seq_data_size*sizeof(char));    fseek(seqfp,0L,SEEK_SET);    for(bp=seq_data_str; (j=fgetc(seqfp))!=EOF; bp++) *bp=j;    *bp = '\0';    fseek(seqfp,0L,SEEK_SET);  }       /* Wait for a DNAML_WORKER_READY from the foreman. This means it has at least * one worker ready for work. But workers are not ready until they have their * sequence data. After process initialization, a worker will send a DNAML_SEQ_ * DATA_REQUEST to the foreman.  The foreman must reply with either a file name * to read (DNAML_SEQ_FILE) or else the data itself (DNAML_SEQ_DATA). If the * foreman has neither, it will forward the request to the master. Regardless, * if we do not get a DNAML_WORKER_READY message within 60 sec we assume some- * thing went wrong and bail. */  t0 = dwalltime00();  do {    from = foreman_id;    type = ANY_TAG;    iprobe_msg(&from,&type);    switch(type) {    case DNAML_SEQ_DATA_REQUEST:  /* from foreman */      recv_msg(NULL,0,from,type);      LOG_SEQ_DATA_REQUEST(from);      if(ship_seq_data) {        send_msg(&seq_data_size,1,from,DNAML_SEQ_DATA_SIZE);        send_msg(seq_data_str,seq_data_size,from,DNAML_SEQ_DATA);        LOG_SENT_SEQDATA(seq_data_size);      }      else {        send_msg(seq_file,sizeof(seq_file),from,DNAML_SEQ_FILE);        LOG_SENT_SEQFILE(seq_file);      }      break;    case DNAML_WORKER_READY:  /*indicates a worker has joined in.*/      recv_msg(&xtid,1,from,type);      break;    case ERR_NO_WORKERS:  /*all workers have quit, so no point continuing.*/      recv_msg(NULL,0,from,type);      end_it_all(ERR_NO_WORKERS);    case DNAML_NOMSG:    default:      break;    }    t1 = dwalltime00();    if(t1-t0>60.0) end_it_all(ERR_TIMEOUT);  } while(type!=DNAML_WORKER_READY);/*  Get data structure memory  */  if (! (adef = (analdef *) Malloc(sizeof(analdef)))) {    printf("ERROR: Unable to get memory for analysis definition\n\n");    end_it_all(0);  }  if (! (rdta = (rawdata *) Malloc(sizeof(rawdata)))) {    printf("ERROR: Unable to get memory for raw DNA\n\n");    end_it_all(0);  }  if (! (cdta = (cruncheddata *) Malloc(sizeof(cruncheddata)))) {    printf("ERROR: Unable to get memory for crunched DNA\n\n");    end_it_all(0);  }  if ((tr = (tree *)     Malloc(sizeof(tree))) &&      (bt = (bestlist *) Malloc(sizeof(bestlist)))) ;  else {    printf("ERROR: Unable to get memory for trees\n\n");    end_it_all(0);  }  bt->ninit = 0;  if(!getinput(seqfp,adef,rdta,cdta,tr))                         end_it_all(0);  if(infol>0 && monitor_id!=INVALID_ID) {    send_msg(&myproc.stats,1,monitor_id,DNAML_INPUT_TIME);  }/* ----- The material below would be a loop over jumbles and/or boots ------ */  if(!makeweights(adef,rdta,cdta))                               end_it_all(0);  if(!makevalues(rdta,cdta))                                     end_it_all(0);  if(adef->empf && !empiricalfreqs(rdta,cdta))                   end_it_all(0);  reportfreqs(adef,rdta);  if(!linkdata2tree(rdta,cdta,tr))                               end_it_all(0);  if(!linkxarray(3,3,cdta->endsite,&freextip,&usedxtip))         end_it_all(0);  if(!setupnodex(tr))                                            end_it_all(0);  if(!initBestTree(bt,adef->nkeep,tr->mxtips,tr->cdta->endsite)) end_it_all(0);  if(!adef->usertree) {    if(!makeDenovoTree(seqfp,tr,bt,adef))                        end_it_all(0);  }  else {    if(!makeUserTree(seqfp,tr,bt,adef))                          end_it_all(0);  }  if(!freeBestTree(bt))                                          end_it_all(0);/* --------- Endpoint for jumble and/or boot loop -------------------------- */  fclose(seqfp);  freeTree(tr);  if(infol>0 && monitor_id!=INVALID_ID) {    send_msg(&myproc.stats,1,monitor_id,DNAML_STEP_TIME);  }  end_it_all(0);} /* DNA Maximum Likelihood *//******************************************************************************* */void end_it_all(int errcode){ /* end_it_all */  char  c;  send_msg(&c,1,foreman_id,DNAML_QUIT);  if(outfp) fclose(outfp);#if DEBUG  (void) fclose(dbgfp);#endif  if(monitor_id!=INVALID_ID) {    record_times(&myproc.stats);    send_msg(&myproc.stats,1,monitor_id,DNAML_DONE);  }  bail(NULL,errcode);} /* end_it_all */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -