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

📄 send_tree.c

📁 fastDNAml is an attempt to solve the same problem as DNAML, but to do so faster and using less memo
💻 C
字号:
#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"/******************************************************************************* *  In the parallel fastDNAml, the master process calls sendTree() to convert *  a tree from internal format into Newick format and send it to the foreman. *  At the end of a round of tree evaluations, or when MAX_SEND_AHEAD trees *  have been sent out, the master calls getReturnedTrees() to request the *  foreman to return the best tree. */# define MAX_SEND_AHEAD 400char    *best_tr_recv = NULL;   /* these are used for flow control */double  best_lk_recv;int     send_ahead = 0;         /* number of outstanding sends */char    c;char    *treestr = NULL;int     ntips = 0;int     siz = 0;int handle_msgs(int block){  int     n;  int     from,tag;  from = ANY_SOURCE;  tag = ANY_TAG;  if(block)    probe_msg(&from,&tag);  else    iprobe_msg(&from,&tag);  switch(tag) {  case DNAML_SEQ_DATA_REQUEST:    recv_msg(NULL,0,from,tag);    send_msg(&seq_data_size,1,from,DNAML_SEQ_DATA_SIZE);    send_msg(seq_data_str,seq_data_size,from,DNAML_SEQ_DATA);    break;  case DNAML_RESULT:    recv_msg(treestr,siz,from,tag);    break;  case DNAML_WORKER_READY:  /*indicates another worker has joined in.*/    recv_msg(&n,1,from,tag);    break;  case ERR_NO_WORKERS:  /*all workers have quit, so no point continuing.*/    recv_msg(NULL,0,from,tag);    end_it_all(ERR_NO_WORKERS);  case DNAML_STATS_REQUEST:    recv_msg(NULL,0,from,tag);    record_times(&myproc.stats);    send_msg(&myproc.stats,1,from,DNAML_STATS);    break;  case DNAML_NOMSG:  default:    break;  }  return tag;}boolean sendTree (tree *tr){ /* sendTree */  int  tag;  if(tr->ntips > ntips) {    Free(treestr);    ntips = tr->ntips;    siz = ntips*(nmlngth+32)+256;    if( !(treestr=(char*)Malloc(siz)) ) {      fprintf(stderr, "sendTree: treestr Malloc failure\n");      return FALSE;    }  }  tag = handle_msgs(0);  if (send_ahead >= MAX_SEND_AHEAD) {    double new_likelihood;    int  n_to_get;    n_to_get = (send_ahead+1)/2;    send_msg(&n_to_get,1,foreman_id,DNAML_NUM_TREE);    send_ahead -= n_to_get;    while( handle_msgs(1)!=DNAML_RESULT );    new_likelihood = str_readTreeLikelihood(treestr);    if (new_likelihood == badEval)  return FALSE;    if (! best_tr_recv || (new_likelihood > best_lk_recv)) {      if (best_tr_recv)  Free(best_tr_recv);      best_tr_recv = Malloc(strlen(treestr) + 1);      strcpy(best_tr_recv, treestr);      best_lk_recv = new_likelihood;    }  }  send_ahead++;  if(infol>3 && monitor_id!=INVALID_ID) {    send_msg(&c,0,monitor_id,DNAML_SEND_TREE);  }  treeString(treestr, tr, tr->start->back, 1);  send_msg(treestr,strlen(treestr),foreman_id,DNAML_WORK);  return TRUE;} /* sendTree */boolean  getReturnedTrees (tree *tr, bestlist *bt, int n_tree_sent) /* n_tree_sent -- number of trees sent to slaves */{ /* getReturnedTrees */  if(tr->ntips > ntips) {    Free(treestr);    ntips = tr->ntips;    siz = ntips*(nmlngth+32)+256;    if( !(treestr=(char*)Malloc(siz)) ) {      fprintf(stderr, "getReturnedTrees: treestr Malloc failure\n");      return FALSE;    }  }  send_msg(&send_ahead,1,foreman_id,DNAML_NUM_TREE);  send_ahead = 0;  while( handle_msgs(1)!=DNAML_RESULT );  if (best_tr_recv) {    if (str_readTreeLikelihood(treestr) < best_lk_recv) {      strcpy(treestr, best_tr_recv);    }     Free(best_tr_recv);    best_tr_recv = NULL;  }   if(!str_treeReadLen(treestr,tr)) return FALSE;  tr->smoothed = TRUE;  (void) saveBestTree(bt, tr);  return TRUE;} /* getReturnedTrees */

⌨️ 快捷键说明

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