示例#1
0
void tcpdemux::remove_all_flows()
{
    for(flow_map_t::iterator it=flow_map.begin();it!=flow_map.end();it++){
        post_process(it->second);
    }
    flow_map.clear();
}
示例#2
0
void enframe()
{
  static uint16_t frame_num = 0;
  if(cbuffer.count < FRAME_SIZE)
    return; //nothing to do
  float32_t fdata[FFT_SIZE] = {0};
  if(frame_num >= NUM_FRAME)
    post_process();

  uint16_t i;
  uint16_t head_length = MAX_BUF_SIZE-cbuffer.header;
  if(head_length < MIN2(FRAME_SIZE,FFT_SIZE))//complex case
  {
    for(i = 0; i < head_length; i++)
      fdata[i] = Hamming[i]*cbuffer.data[cbuffer.header+i];
    for(i = 0; i < MIN2(FRAME_SIZE,FFT_SIZE)-head_length; i++)
      fdata[head_length+i] = Hamming[head_length+i]*cbuffer.data[i];
  }
  else //simple case
    for(i = 0; i < MIN2(FRAME_SIZE,FFT_SIZE); ++i) //SIMD not available
      fdata[i] = Hamming[i]*cbuffer.data[cbuffer.header+i];
#if(FFT_SIZE > FRAME_SIZE)
  memset(fdata+FRAME_SIZE, 0, (FFT_SIZE-FRAME_SIZE+1)*sizeof(float32_t));//zero padding
#endif
  cbuffer.count -= FRAME_SHIFT; //counter modification
  cbuffer.header += FRAME_SHIFT;
  if(cbuffer.header >= MAX_BUF_SIZE)
    cbuffer.header -= MAX_BUF_SIZE;

  mfcc(fdata, feature_vec[frame_num]);
  post_proc_callback(&feature_vec[0][0], frame_num);
  frame_num++;
}
示例#3
0
void tcpdemux::remove_flow(const flow_addr &flow)
{
    flow_map_t::iterator it = flow_map.find(flow);
    if(it!=flow_map.end()){
        post_process(it->second);
	flow_map.erase(it);
    }
}
示例#4
0
void extract_jsa_candidate(jsa_solutiont &solution, const jsa_programt &prog,
    const goto_tracet &trace, const pred_op_idst &pred_ops,
    const pred_op_idst &result_pred_ops, const size_t max_size)
{
  jsa_genetic_solutiont tmp;
  extract_jsa_genetic_candidate(tmp, prog, trace);
  post_process(tmp, pred_ops, result_pred_ops, max_size);
  solution=convert(tmp, prog);
}
示例#5
0
decision_proceduret::resultt bv_refinementt::dec_solve()
{
  // do the usual post-processing
  status() << "BV-Refinement: post-processing" << eom;
  post_process();

  debug() << "Solving with " << prop.solver_text() << eom;
  
  unsigned iteration=0;
  
  // now enter the loop
  while(true)
  {
    iteration++;
  
    status() << "BV-Refinement: iteration " << iteration << eom;

    // output the very same information in a structured fashion
    if(ui==ui_message_handlert::XML_UI)
    {
      xmlt xml("refinement-iteration");
      xml.data=i2string(iteration);
      std::cout << xml << '\n';
    }

    switch(prop_solve())
    {
    case D_SATISFIABLE:
      check_SAT();
      if(!progress)
      {
        status() << "BV-Refinement: got SAT, and it simulates => SAT" << eom;
        status() << "Total iterations: " << iteration << eom;
        return D_SATISFIABLE;
      }
      else
        status() << "BV-Refinement: got SAT, and it is spurious, refining" << eom;
      break;

    case D_UNSATISFIABLE:
      check_UNSAT();
      if(!progress)
      {
        status() << "BV-Refinement: got UNSAT, and the proof passes => UNSAT" << eom;
        status() << "Total iterations: " << iteration << eom;
        return D_UNSATISFIABLE;
      }
      else
        status() << "BV-Refinement: got UNSAT, and the proof fails, refining" << eom;
      break;
    
    default:
      return D_ERROR;
    }
  }
}
示例#6
0
void
GraphImpl::process(ProcessContext& context)
{
	if (!_process)
		return;

	pre_process(context);
	run(context);
	post_process(context);
}
示例#7
0
文件: file.c 项目: andreiw/polaris
static int
process_file(Elf *elf, char *cur_file, Cmd_Info *cmd_info)
{
	int error = SUCCESS;
	int x;
	GElf_Ehdr ehdr;
	size_t shnum;

	/*
	 * Initialize
	 */
	if (gelf_getehdr(elf, &ehdr) == NULL) {
		error_message(LIBELF_ERROR,
		LIBelf_ERROR, elf_errmsg(-1), prog);
		return (FAILURE);
	}

	if (elf_getshnum(elf, &shnum) == NULL) {
		error_message(LIBELF_ERROR,
		LIBelf_ERROR, elf_errmsg(-1), prog);
		return (FAILURE);
	}

	initialize(shnum, cmd_info);

	if (ehdr.e_phnum != 0) {
		if (build_segment_table(elf, &ehdr) == FAILURE)
			return (FAILURE);
	}

	if ((x = traverse_file(elf, &ehdr, cur_file, cmd_info)) ==
	    FAILURE) {
		error_message(WRN_MANIPULATED_ERROR,
		PLAIN_ERROR, (char *)0,
		prog, cur_file);
		error = FAILURE;
	} else if (x != DONT_BUILD && x != FAILURE) {
		post_process(cmd_info);
		if (build_file(elf, &ehdr, cmd_info) == FAILURE) {
			error_message(WRN_MANIPULATED_ERROR,
			PLAIN_ERROR, (char *)0,
			prog, cur_file);
			error = FAILURE;
		}
	}

	free(off_table);
	free(sec_table);
	free(nobits_table);

	if (x == DONT_BUILD)
		return (DONT_BUILD);
	else
		return (error);
}
示例#8
0
/**
 * This uses link_array.  It post-processes
 * this linkage, and prints the appropriate thing.  There are no fat
 * links in it.
 */
Linkage_info analyze_thin_linkage(Sentence sent, Parse_Options opts, int analyze_pass)
{
	int i;
	Linkage_info li;
	PP_node * pp;
	Postprocessor * postprocessor;
	Sublinkage *sublinkage;
	Parse_info pi = sent->parse_info;

	build_digraph(pi, word_links);
	memset(&li, 0, sizeof(li));

	sublinkage = x_create_sublinkage(pi);
	postprocessor = sent->dict->postprocessor;

	compute_link_names(sent);
	for (i=0; i<pi->N_links; i++) {
	  copy_full_link(&(sublinkage->link[i]), &(pi->link_array[i]));
	}

	if (analyze_pass==PP_FIRST_PASS) {
		post_process_scan_linkage(postprocessor, opts, sent, sublinkage);
		free_sublinkage(sublinkage);
		free_digraph(pi, word_links);
		return li;
	}

	/* The code below can be used to generate the "islands" array. For this to work,
	 * however, you have to call "build_digraph" first (as in analyze_fat_linkage).
	 * and then "free_digraph". For some reason this causes a space leak. */

	pp = post_process(postprocessor, opts, sent, sublinkage, TRUE);

	li.N_violations = 0;
	li.and_cost = 0;
	li.unused_word_cost = unused_word_cost(sent->parse_info);
	li.improper_fat_linkage = FALSE;
	li.inconsistent_domains = FALSE;
	li.disjunct_cost = disjunct_cost(pi);
	li.null_cost = null_cost(pi);
	li.link_cost = link_cost(pi);
	li.andlist = NULL;

	if (pp==NULL) {
		if (postprocessor != NULL) li.N_violations = 1;
	} else if (pp->violation!=NULL) {
		li.N_violations++;
	}

	free_sublinkage(sublinkage);
	free_digraph(pi, word_links);
	return li;
}
示例#9
0
__DEVICE__
void exec_update_and_postprocess (CDATAFORMAT min_time, solver_props *props, unsigned int modelid, int resuming) {
  int i;
  for(i=0;i<NUM_ITERATORS;i++){
    if(props[i].running[modelid] && (!resuming || props[i].next_time[modelid] == min_time)){
      props[i].dirty_states[modelid] = 0 == update(&props[i], modelid);
    }	  
    if(props[i].running[modelid] && (resuming && props[i].next_time[modelid] == min_time)){
      props[i].dirty_states[modelid] |= 0 == post_process(&props[i], modelid);
    }
  }
}
std::string &post_process_fitness_source(std::string &result,
    const symbol_tablet &st, const goto_functionst &gf,
    const size_t num_ce_vars, const size_t num_vars, const size_t num_consts,
    const size_t max_prog_size, const std::string &exec)
{
  const namespacet ns(st);
  std::stringstream ss;
  dump_c(gf, true, ns, ss);
  add_first_prog_offset(result, num_ce_vars);
  add_assume_implementation(result);
  add_danger_execute(result, num_vars, num_consts, max_prog_size, exec);
  return post_process(result, ss);
}
示例#11
0
int main(int argc, char** argv)
{
	uint8_t inbuf[SIZE];
	uint8_t outbuf[SIZE];

	// Test SHA-3
	pp_data data;
	data.type = SHA3;
	data.input_data.sample = inbuf;
	data.output_data = outbuf;
	post_process(&data);

	return 0;
}
示例#12
0
t_list		*tokenize_prompt(t_context *context, char *format)
{
	t_token	token;
	int		ret;
	t_list	*tokens;

	tokens = 0;
	while ((ret = read_token(&format, &token)) == 1)
		ft_lstappend(&tokens, ft_lstnew(&token, sizeof(t_token)));
	if (ret == -1)
		ft_lstdel(&tokens, free_token);
	post_process(context, tokens);
	return (tokens);
}
示例#13
0
intermediate_model
intermediate_model_factory::intermediate_model_for_descriptor(
    const annotations::annotation_groups_factory& agf,
    const annotations::type_repository& atrp,
    frontend_registrar& rg, const descriptor& d) const {
    BOOST_LOG_SEV(lg, debug) << "Creating intermediate model. "
                             << "Descriptor: " << d;

    auto& f(rg.frontend_for_extension(d.extension()));
    auto r(f.read(d));
    post_process(agf, atrp, r);

    BOOST_LOG_SEV(lg, debug) << "Created intermediate model.";
    return r;
}
示例#14
0
decision_proceduret::resultt dplib_dect::dec_solve()
{
  dplib_prop.out << "QUERY FALSE;" << std::endl;
  dplib_prop.out << "COUNTERMODEL;" << std::endl;
  
  post_process();

  temp_out.close();

  temp_result_filename=
    "dplib_dec_result_"+i2string(getpid())+".tmp";
    
  std::string command=
    "dplibl "+temp_out_filename+" > "+temp_result_filename+" 2>&1";
    
  system(command.c_str());
  
  status("Reading result from CVCL");

  return read_dplib_result();
}
示例#15
0
int main(int argc, char **argv)
{
	XMLParserContext *h;
	int i;
	if(argc != 3)
	{
		printf("error input args\n");
		system("pause");
		return 0;
	}
	h = read_XML_file(argv[1]);

	for(i = 0; i < h->i_count_data_sets; i++)
	{
		parse_events(h, i);
		post_process(h, i);
	}

	release_XML_file(h, argv[2]);

	system("pause");
	return 0;
}
示例#16
0
int main(int argc, char* argv[])
{
  // Check arguments
  if (argc < 3) {
    std::cerr << "Usage: shallow_water NODES_FILE TRIS_FILE\n";
    exit(1);
  }

  MeshType mesh;
  // HW4B: Need node_type before this can be used!
#if 1
  std::vector<typename MeshType::node_type> mesh_node;
#endif

  // Read all Points and add them to the Mesh
  std::ifstream nodes_file(argv[1]);
  Point p;
  while (CS207::getline_parsed(nodes_file, p)) {
    // HW4B: Need to implement add_node before this can be used!
#if 1
    mesh_node.push_back(mesh.add_node(p));
#endif
  }

  // Read all mesh triangles and add them to the Mesh
  std::ifstream tris_file(argv[2]);
  std::array<int,3> t;
  while (CS207::getline_parsed(tris_file, t)) {
    // HW4B: Need to implement add_triangle before this can be used!
#if 1
    mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]);
#endif
  }

  // Print out the stats
  std::cout << mesh.num_nodes() << " "
            << mesh.num_edges() << " "
            << mesh.num_triangles() << std::endl;

  // HW4B Initialization
  // Set the initial conditions according the type of input pattern
  if(argv[2][5]=='d'){
    Dam<MeshType> init;
    for(auto it= mesh.node_begin(); it != mesh.node_end(); ++it)
      init(*it);
    }
  else if((argv[2][5]=='p')){
    Pebble<MeshType> init;
    for(auto it= mesh.node_begin(); it != mesh.node_end(); ++it)
      init(*it);
    }
  else{
    Wave<MeshType> init;
    for(auto it= mesh.node_begin(); it != mesh.node_end(); ++it)
      init(*it);
    }

  // Set triangle values
  for (auto it=mesh.triangle_begin(); it!=mesh.triangle_end(); ++it) {
    (*it).value().Q = QVar(0.0,0.0,0.0);
    (*it).value().Q += (*it).node(0).value().Q;
    (*it).value().Q += (*it).node(1).value().Q;
    (*it).value().Q += (*it).node(2).value().Q;
    (*it).value().Q /= 3.0;
  }
 

  // Launch the SDLViewer
  CS207::SDLViewer viewer;
  viewer.launch();


  // HW4B: Need to define Mesh::node_type and node/edge iterator
  // before these can be used!
#if 1
  auto node_map = viewer.empty_node_map(mesh);
  viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                   CS207::DefaultColor(), NodePosition(), node_map);
  viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map);
#endif
  viewer.center_view();


  // HW4B: Timestep
  // CFL stability condition requires dt <= dx / max|velocity|
  // For the shallow water equations with u = v = 0 initial conditions
  //   we can compute the minimum edge length and maximum original water height
  //   to set the time-step
  // Compute the minimum edge length and maximum water height for computing dt
  double min_edge_length =( *mesh.edge_begin()).length();
  for (auto it=mesh.edge_begin(); it!=mesh.edge_end(); ++it) {
    if ((*it).length() < min_edge_length) {
      min_edge_length = (*it).length();
    }
  }
  double max_height = 0.0;
  for (auto it=mesh.node_begin(); it!=mesh.node_end(); ++it) {
    if ((*it).value().Q.h > max_height) {
      max_height = (*it).value().Q.h;
    }
  }
  
#if 1

  double dt = 0.25 * min_edge_length / (sqrt(grav * max_height));
#else
  // Placeholder!! Delete me when min_edge_length and max_height can be computed!
  double dt = 0.1;
#endif
  double t_start = 0;
  double t_end = 10;

  // Preconstruct a Flux functor
  EdgeFluxCalculator f;

  // Begin the time stepping
  for (double t = t_start; t < t_end; t += dt) {
    //print(mesh, t);
    // Step forward in time with forward Euler
    hyperbolic_step(mesh, f, t, dt);

    // Update node values with triangle-averaged values
    post_process(mesh);

    // Update the viewer with new node positions
    // HW4B: Need to define node_iterators before these can be used!
#if 1
    viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                     CS207::DefaultColor(), NodePosition(), node_map);
#endif
    viewer.set_label(t);

    // These lines slow down the animation for small meshes.
    // Feel free to remove them or tweak the constants.
    if (mesh.num_nodes() < 100)
      CS207::sleep(0.05);
  }

  return 0;
}
示例#17
0
int main( int argc, char *argv[])
{
   static FLOAT  synth_buf[L_FRAME+M];     /* Synthesis                  */
   FLOAT  *synth;
   static int parm[PRM_SIZE+2];            /* Synthesis parameters + BFI */
   static INT16 serial[SERIAL_SIZE];       /* Serial stream              */
   static FLOAT  Az_dec[MP1*2];            /* Decoded Az for post-filter */
   static int T2[2];                       /* Decoded Pitch              */

   INT32 frame;
   int i;
   FILE   *f_syn, *f_serial;


   printf("\n");
   printf("**************    G.729A 8 KBIT/S SPEECH DECODER    ************\n");
   printf("\n");
   printf("----------------- Floating point C simulation ----------------\n");
   printf("\n");
   printf("------------ Version 1.01 (Release 2, November 2006) --------\n");
   printf("\n");

   /* Passed arguments */

   if ( argc != 3)
     {
        printf("Usage :%s bitstream_file  outputspeech_file\n",argv[0]);
        printf("\n");
        printf("Format for bitstream_file:\n");
        printf("  One (2-byte) synchronization word \n");
        printf("  One (2-byte) size word,\n");
        printf("  80 words (2-byte) containing 80 bits.\n");
        printf("\n");
        printf("Format for outputspeech_file:\n");
        printf("  Synthesis is written to a binary file of 16 bits data.\n");
        exit( 1 );
     }

   /* Open file for synthesis and packed serial stream */

   if( (f_serial = fopen(argv[1],"rb") ) == NULL )
     {
        printf("%s - Error opening file  %s !!\n", argv[0], argv[1]);
        exit(0);
     }

   if( (f_syn = fopen(argv[2], "wb") ) == NULL )
     {
        printf("%s - Error opening file  %s !!\n", argv[0], argv[2]);
        exit(0);
     }

   printf("Input bitstream file  :   %s\n",argv[1]);
   printf("Synthesis speech file :   %s\n",argv[2]);

/*-----------------------------------------------------------------*
 *           Initialization of decoder                             *
 *-----------------------------------------------------------------*/

  for (i=0; i<M; i++) synth_buf[i] = (F)0.0;
  synth = synth_buf + M;

  bad_lsf = 0;          /* Initialize bad LSF indicator */
  init_decod_ld8a();
  init_post_filter();
  init_post_process();

/*-----------------------------------------------------------------*
 *            Loop for each "L_FRAME" speech data                  *
 *-----------------------------------------------------------------*/

   frame =0;
   while( fread(serial, sizeof(INT16), SERIAL_SIZE, f_serial) == SERIAL_SIZE)
   {
      frame++;
      printf(" Frame: %ld\r", frame);

      bits2prm_ld8k( &serial[2], &parm[1]);

      if (serial[0] == SYNC_WORD) {
         parm[0] = 0;           /* No frame erasure */
      } else {
         parm[0] = 1;           /* frame erased     */
      }

      parm[4] = check_parity_pitch(parm[3], parm[4] ); /* get parity check result */

      decod_ld8a(parm, synth, Az_dec, T2);             /* decoder */

      post_filter(synth, Az_dec, T2);                  /* Post-filter */

      post_process(synth, L_FRAME);                    /* Highpass filter */

      fwrite16(synth, L_FRAME, f_syn);
   }

   return(0);
}
 //--------------------------------------------------------
 //  finish
 //    finalize state of nodal atomic quantities
 //--------------------------------------------------------
 void ElasticTimeIntegratorVerlet::finish()
 {
   post_process();
 }
 //--------------------------------------------------------
 //  finish
 //    finalize state of nodal atomic quantities
 //--------------------------------------------------------
 void ElasticTimeIntegratorFractionalStep::finish()
 {
   post_process();
 }
示例#20
0
int main(int argc, char **argv)
{
    FILE   *fp, *fp2, *pipe;
    char   testName[32] = "MPI_Allreduce", file1[64], file2[64], pipeStr[8];
    int    dblSize, proc, nprocs, nodeCPUs, nodes;
    unsigned int i, j, size, localSize, NLOOP = NLOOP_MAX;
    unsigned int smin = MIN_COL_SIZE, smed = MED_COL_SIZE, smax = MAX_COL_SIZE;
    double tScale = USEC, bwScale = MB_8;
    double tStart, timeMin, timeMinGlobal, overhead, threshold_lo, threshold_hi;
    double msgBytes, sizeBytes, UsedMem, localMax;
    double tElapsed[NREPS], tElapsedGlobal[NREPS];
    double *A, *B;

    pipe = popen( "cat /proc/cpuinfo | grep processor | wc -l", "r" );
    fgets( pipeStr, 8, pipe ); pclose(pipe);
    nodeCPUs = atoi(pipeStr);

    // Initialize parallel environment
    MPI_Init( &argc, &argv );
    MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
    MPI_Comm_rank( MPI_COMM_WORLD, &proc );

    // Reset maximum message size to fit within node memory
    if( nprocs > nodeCPUs ){
        nodes = nprocs / nodeCPUs;
        if( smax > nodes ) smax = smax / nodes;
        if( smed > nodes ) smed = smed / nodes;
    }

    // Check for user defined limits
    checkEnvCOL( proc, &NLOOP, &smin, &smed, &smax );

    // Initialize local variables
    dblSize = sizeof(double);
    UsedMem = (double)smax*(double)dblSize*(double)( nprocs + 1 );

    // Allocate and initialize arrays
    srand( SEED );
    A = doubleVector( smax );
    B = doubleVector( smax*nprocs );

    // Open output file and write header
    if( proc == 0 ){
        // Check timer overhead in seconds
        timerTest( &overhead, &threshold_lo, &threshold_hi );
        // Open output files and write headers
        sprintf( file1, "allreduce_time-np_%.4d.dat", nprocs );
        sprintf( file2, "allreduce_bw-np_%.4d.dat",   nprocs );
        fp  = fopen( file1, "a" );
        fp2 = fopen( file2, "a" );
        printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );
    }

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup with a medium size message
    MPI_Allreduce( A, B, smed, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
    // Test is current NLOOP is enough to capture fastest test cases
    MPI_Barrier( MPI_COMM_WORLD );
    tStart = benchTimer();
    for(j = 0; j < NLOOP; j++){
        MPI_Allreduce( A, B, smin, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
    }
    timeMin = benchTimer() - tStart;
    MPI_Reduce( &timeMin, &timeMinGlobal, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
    if( proc == 0 ) resetInnerLoop( timeMinGlobal, threshold_lo, &NLOOP );
    MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    localMax = 0.0;
    for( size = smin; size <= smax; size = size*2 ){

        // Warmup with a medium size message
        MPI_Allreduce( A, B, smed, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );

        // Repeat NREPS to collect statistics
        for(i = 0; i < NREPS; i++){
            MPI_Barrier( MPI_COMM_WORLD );
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                MPI_Allreduce( A, B, size, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        MPI_Reduce( tElapsed, tElapsedGlobal, NREPS, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );   
        // Only task 0 needs to do the analysis of the collected data
        if( proc == 0 ){
            // sizeBytes is size to write to file
            // msgBytes is actual data exchanged on the wire
            msgBytes  = (double)size*(double)nprocs*(double)dblSize;
            sizeBytes = (double)size*(double)dblSize;
            post_process( fp, fp2, threshold_hi, tElapsedGlobal, tScale, 
                          bwScale, size*dblSize, sizeBytes, msgBytes, &NLOOP, 
                          &localMax, &localSize );
        }
        MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD ); 
    }
    //================================================================
    // Print completion message, free memory and exit                  
    //================================================================
    if( proc == 0 ){
        fclose(fp);
        fclose(fp2);
        fprintf( stdout,"\n %s test completed.\n\n", testName );
    }
    free( A );
    free( B );

    MPI_Finalize();
    return 0;
}
 //--------------------------------------------------------
 //  finish
 //    finalize state of nodal atomic quantities
 //--------------------------------------------------------
 void FluidsTimeIntegratorGear::finish()
 {
   post_process();
 }
示例#22
0
int main(int argc, char **argv) {
	if(argc != 2) {
		fprintf(stderr, "%s <original boot.img> #This program will take local 'kernel' 'second' 'dt' 'ramdisk' files\n", argv[0]);
	}

	//TODO: Merge with extract.c?
	//{
	int ifd = open(argv[1], O_RDONLY);
	off_t isize = lseek(ifd, 0, SEEK_END);
	lseek(ifd, 0, SEEK_SET);
	uint8_t *iorig = mmap(NULL, isize, PROT_READ, MAP_SHARED, ifd, 0);
	uint8_t *ibase = iorig;
	assert(ibase);

	while(ibase<(iorig+isize)) {
		if(memcmp(ibase, BOOT_MAGIC, BOOT_MAGIC_SIZE) == 0)
			break;
		ibase += 256;
	}
	assert(ibase < (iorig+isize));
	//}
	//
	struct boot_img_hdr *ihdr = (struct boot_img_hdr*) ibase;
	assert(
			ihdr->page_size == 2048 ||
			ihdr->page_size == 4096
			);

	unlink("new-boot.img");
	int ofd = open("new-boot.img", O_RDWR|O_CREAT, 0644);
	ftruncate(ofd, ihdr->page_size);
	//Write back original header, we'll change it later
	write(ofd, ihdr, sizeof(*ihdr));

	struct boot_img_hdr *hdr = mmap(NULL, sizeof(*ihdr), PROT_READ|PROT_WRITE, MAP_SHARED, ofd, 0);
	//First set everything to zero, so we know where we are at.
	hdr->kernel_size = 0;
	hdr->ramdisk_size = 0;
	hdr->second_size = 0;
	hdr->unused[0] = 0;
	memset(hdr->id, 0, sizeof(hdr->id)); //Setting id to 0 might be wrong?

	int pos = hdr->page_size;
	int size = 0;

	size = append_file(ofd, "kernel", pos);
	pos += size + hdr->page_size - 1;
	pos &= ~(hdr->page_size-1);
	hdr->kernel_size = size;

	size = append_ramdisk(ofd, pos);
	pos += size + hdr->page_size - 1;
	pos &= ~(hdr->page_size-1);
	hdr->ramdisk_size = size;

	if(access("second", R_OK) == 0) {
		size = append_file(ofd, "second", pos);
		pos += size + hdr->page_size - 1;
		pos &= ~(hdr->page_size-1);
		hdr->second_size = size;
	}

	if(access("dt", R_OK) == 0) {
		size = append_file(ofd, "dt", pos);
		pos += size + hdr->page_size - 1;
		pos &= ~(hdr->page_size-1);
		hdr->unused[0] = size;
	}

	post_process(hdr, ofd, pos);
	munmap(hdr, sizeof(*ihdr));
	close(ofd);

	return 0;
}
示例#23
0
int main(int argc, char **argv)
{
    FILE    *fp, *fp2;
    char    testName[32] = "MPI_Get_Fence", file1[64], file2[64];
    int     dblSize, proc, nprocs, npairs, partner;
    unsigned int i, j, k, size, localSize, NLOOP = NLOOP_MAX;
    unsigned int smin = MIN_P2P_SIZE, smed = MED_P2P_SIZE, smax = MAX_P2P_SIZE;
    double  tScale = USEC, bwScale = MB_8;
    double  tStart, timeMin, timeMinGlobal, overhead, threshold_lo, threshold_hi;
    double  msgBytes, sizeBytes, localMax, UsedMem;
    double  tElapsed[NREPS], tElapsedGlobal[NREPS];
    double  *A, *B;
    MPI_Win   win;

    // Initialize parallel environment
    MPI_Init(&argc, &argv);
    MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
    MPI_Comm_rank( MPI_COMM_WORLD, &proc );

    // Test input parameters
    if( nprocs%2 != 0 && proc == 0 )
        fatalError( "P2P test requires an even number of processors" );

    // Check for user defined limits
    checkEnvP2P( proc, &NLOOP, &smin, &smed, &smax );

    // Initialize local variables
    localMax = 0.0;
    npairs   = nprocs/2;
    if( proc < npairs  ) partner = proc + npairs;
    if( proc >= npairs ) partner = proc - npairs;
    UsedMem = (double)smax*(double)sizeof(double)*2.0;

    // Allocate and initialize arrays
    srand( SEED );
    A = doubleVector( smax );
    B = doubleVector( smax );

    // Open output file and write header
    if( proc == 0 ){
        // Check timer overhead in seconds
        timerTest( &overhead, &threshold_lo, &threshold_hi );
        // Open output files and write headers
        sprintf( file1, "getfence_time-np_%.4d.dat", nprocs );
        sprintf( file2, "getfence_bw-np_%.4d.dat",   nprocs );
        fp  = fopen( file1, "a" );
        fp2 = fopen( file2, "a" );
        printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );
    }

    // Get type size
    MPI_Type_size( MPI_DOUBLE, &dblSize );
    // Set up a window for RMA
    MPI_Win_create( A, smax*dblSize, dblSize, MPI_INFO_NULL, MPI_COMM_WORLD, &win );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup with a medium size message
    if( proc < npairs ){
        MPI_Win_fence( 0, win );
        MPI_Get( B, smed, MPI_DOUBLE, partner, 0, smed, MPI_DOUBLE, win );
        MPI_Win_fence( 0, win );
    }else{
        MPI_Win_fence( 0, win );
        MPI_Win_fence( 0, win );
    }
    // Test if current NLOOP is enough to capture fastest test cases
    MPI_Barrier( MPI_COMM_WORLD );
    tStart = benchTimer();
    if( proc < npairs ){
        for(j = 0; j < NLOOP; j++){
            MPI_Win_fence( 0, win );
        	MPI_Get( B, smin, MPI_DOUBLE, partner, 0, smin, MPI_DOUBLE, win );
            MPI_Win_fence( 0, win );
        }
    }else{
        for(j = 0; j < NLOOP; j++){
            MPI_Win_fence( 0, win );
            MPI_Win_fence( 0, win );
        }
    }
    timeMin = benchTimer() - tStart;
    MPI_Reduce( &timeMin, &timeMinGlobal, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
    if( proc == 0 ) resetInnerLoop( timeMinGlobal, threshold_lo, &NLOOP );
    MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );


    //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        // Warmup with a medium size message
        if( proc < npairs ){
            MPI_Win_fence( 0, win );
            MPI_Get( B, smed, MPI_DOUBLE, partner, 0, smed, MPI_DOUBLE, win );
            MPI_Win_fence( 0, win );
        }else{
            MPI_Win_fence( 0, win );
            MPI_Win_fence( 0, win );
        }

        // Repeat NREPS to collect statistics
        for(i = 0; i < NREPS; i++){
            MPI_Barrier( MPI_COMM_WORLD );
            tStart = benchTimer();
            if( proc < npairs ){
                for(j = 0; j < NLOOP; j++){
                    MPI_Win_fence( 0, win );
        	        MPI_Get( B, size, MPI_DOUBLE, partner, 0, size, MPI_DOUBLE, win );
                    MPI_Win_fence( 0, win );
                }
            }else{
                for(j = 0; j < NLOOP; j++){
                    MPI_Win_fence( 0, win );
                    MPI_Win_fence( 0, win );
                }
            }
        	tElapsed[i] = benchTimer() - tStart;
        }
        MPI_Reduce( tElapsed, tElapsedGlobal, NREPS, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
        // Only task 0 needs to do the analysis of the collected data
        if( proc == 0 ){
            // sizeBytes is size to write to file
            // msgBytes is actual data exchanged on the wire
            msgBytes  = (double)size*(double)npairs*(double)dblSize;
            sizeBytes = (double)size*(double)dblSize;
            post_process( fp, fp2, threshold_hi, tElapsedGlobal, tScale, 
                          bwScale, size*dblSize, sizeBytes, msgBytes, &NLOOP, 
                          &localMax, &localSize );
        }
        MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );

    }
    MPI_Win_free( &win );
    MPI_Barrier( MPI_COMM_WORLD );
    free( A );
    free( B );

    //================================================================
    // Print completion message, free memory and exit                  
    //================================================================
    if( proc == 0 ){
        printSummary( fp2, testName, localMax, localSize );
        fclose( fp2 ); 
        fclose( fp );
    }

    MPI_Finalize();
    return 0;
}
示例#24
0
/**
 * This uses link_array.  It enumerates and post-processes
 * all the linkages represented by this one.  We know this contains
 * at least one fat link.
 */
Linkage_info analyze_fat_linkage(Sentence sent, Parse_Options opts, int analyze_pass)
{
	int i;
	Linkage_info li;
	DIS_node *d_root;
	PP_node *pp;
	Postprocessor *postprocessor;
	Sublinkage *sublinkage;
	Parse_info pi = sent->parse_info;
	PP_node accum;			   /* for domain ancestry check */
	D_type_list * dtl0, * dtl1;  /* for domain ancestry check */

	sublinkage = x_create_sublinkage(pi);
	postprocessor = sent->dict->postprocessor;
	build_digraph(pi, word_links);
	structure_violation = FALSE;
	d_root = build_DIS_CON_tree(pi, word_links); /* may set structure_violation to TRUE */

	li.N_violations = 0;
	li.improper_fat_linkage = structure_violation;
	li.inconsistent_domains = FALSE;
	li.unused_word_cost = unused_word_cost(sent->parse_info);
	li.disjunct_cost = disjunct_cost(pi);
	li.null_cost = null_cost(pi);
	li.link_cost = link_cost(pi);
	li.and_cost = 0;
	li.andlist = NULL;

	if (structure_violation) {
		li.N_violations++;
		free_sublinkage(sublinkage);
		free_digraph(pi, word_links);
		free_DIS_tree(d_root);
		return li;
	}

	if (analyze_pass==PP_SECOND_PASS) {
	  li.andlist = build_andlist(sent, word_links);
	  li.and_cost = li.andlist->cost;
	}
	else li.and_cost = 0;

	compute_link_names(sent);

	for (i=0; i<pi->N_links; i++) accum.d_type_array[i] = NULL;

	for (;;) {		/* loop through all the sub linkages */
		for (i=0; i<pi->N_links; i++) {
			patch_array[i].used = patch_array[i].changed = FALSE;
			patch_array[i].newl = pi->link_array[i].l;
			patch_array[i].newr = pi->link_array[i].r;
			copy_full_link(&sublinkage->link[i], &(pi->link_array[i]));
		}
		fill_patch_array_DIS(d_root, NULL, word_links);

		for (i=0; i<pi->N_links; i++) {
			if (patch_array[i].changed || patch_array[i].used) {
				sublinkage->link[i]->l = patch_array[i].newl;
				sublinkage->link[i]->r = patch_array[i].newr;
			}
			else if ((dfs_root_word[pi->link_array[i].l] != -1) &&
					 (dfs_root_word[pi->link_array[i].r] != -1)) {
				sublinkage->link[i]->l = -1;
			}
		}

		compute_pp_link_array_connectors(sent, sublinkage);
		compute_pp_link_names(sent, sublinkage);

		/* 'analyze_pass' logic added ALB 1/97 */
		if (analyze_pass==PP_FIRST_PASS) {
			post_process_scan_linkage(postprocessor,opts,sent,sublinkage);
			if (!advance_DIS(d_root)) break;
			else continue;
		}

		pp = post_process(postprocessor, opts, sent, sublinkage, TRUE);

		if (pp==NULL) {
			if (postprocessor != NULL) li.N_violations = 1;
		}
		else if (pp->violation == NULL)  {
			/* the purpose of this stuff is to make sure the domain
			   ancestry for a link in each of its sentences is consistent. */

			for (i=0; i<pi->N_links; i++) {
				if (sublinkage->link[i]->l == -1) continue;
				if (accum.d_type_array[i] == NULL) {
					accum.d_type_array[i] = copy_d_type(pp->d_type_array[i]);
				} else {
					dtl0 = pp->d_type_array[i];
					dtl1 = accum.d_type_array[i];
					while((dtl0 != NULL) && (dtl1 != NULL) && (dtl0->type == dtl1->type)) {
						dtl0 = dtl0->next;
						dtl1 = dtl1->next;
					}
					if ((dtl0 != NULL) || (dtl1 != NULL)) break;
				}
			}
			if (i != pi->N_links) {
				li.N_violations++;
				li.inconsistent_domains = TRUE;
			}
		}
		else if (pp->violation!=NULL) {
			li.N_violations++;
		}

		if (!advance_DIS(d_root)) break;
	}

	for (i=0; i<pi->N_links; ++i) {
		free_d_type(accum.d_type_array[i]);
	}

	/* if (display_on && (li.N_violations != 0) &&
	   (verbosity > 3) && should_print_messages)
	   printf("P.P. violation in one part of conjunction.\n"); */
	free_sublinkage(sublinkage);
	free_digraph(pi, word_links);
	free_DIS_tree(d_root);
	return li;
}
示例#25
0
/*************************************************************************
 * Entry point for ama
 *************************************************************************/
int main(int argc, char **argv) {
  AMA_OPTIONS_T options;
  ARRAYLST_T *motifs;
  clock_t c0, c1; // measuring cpu_time
  MOTIF_AND_PSSM_T *combo;
  CISML_T *cisml;
  PATTERN_T** patterns;
  PATTERN_T *pattern;
  FILE *fasta_file, *text_output, *cisml_output;
  int i, seq_loading_num, seq_counter, unique_seqs, seq_len, scan_len, x1, x2, y1, y2;
  char *seq_name, *path;
  bool need_postprocessing, created;
  SEQ_T *sequence;
  RBTREE_T *seq_ids;
  RBNODE_T *seq_node;
  double *logcumback;
  ALPH_T *alph;

  // process the command
  process_command_line(argc, argv, &options);

  // load DNA motifs
  motifs = load_motifs(&options);

  // get the alphabet
  if (arraylst_size(motifs) > 0) {
    combo = (MOTIF_AND_PSSM_T*)arraylst_get(0, motifs);
    alph = alph_hold(get_motif_alph(combo->motif));
  } else {
    alph = alph_dna();
  }

  // pick columns for GC operations
  x1 = -1; x2 = -1; y1 = -1; y2 = -1;
  if (alph_size_core(alph) == 4 && alph_size_pairs(alph) == 2) {
    x1 = 0; // A
    x2 = alph_complement(alph, x1); // T
    y1 = (x2 == 1 ? 2 : 1); // C
    y2 = alph_complement(alph, y1); // G
    assert(x1 != x2 && y1 != y2 && x1 != y1 && x2 != y2 && x1 != y2 && x2 != y1);
  }

  // record starting time
  c0 = clock();

  // Create cisml data structure for recording results
  cisml = allocate_cisml(PROGRAM_NAME, options.command_line, options.motif_filename, options.fasta_filename);
  set_cisml_background_file(cisml, options.bg_filename);

  // make a CISML pattern to hold scores for each motif
  for (i = 0; i < arraylst_size(motifs); i++) {
    combo = (MOTIF_AND_PSSM_T*)arraylst_get(i, motifs);
    add_cisml_pattern(cisml, allocate_pattern(get_motif_id(combo->motif), ""));
  }

  // Open the FASTA file for reading.
  fasta_file = NULL;
  if (!open_file(options.fasta_filename, "r", false, "FASTA", "sequences", &fasta_file)) {
    die("Couldn't open the file %s.\n", options.fasta_filename);
  }
  if (verbosity >= NORMAL_VERBOSE) {
    if (options.last == 0) {
      fprintf(stderr, "Using entire sequence\n");
    } else {
      fprintf(stderr, "Limiting sequence to last %d positions.\n", options.last);
    }
  }

  //
  // Read in all sequences and score with all motifs
  //
  seq_loading_num = 0;  // keeps track on the number of sequences read in total
  seq_counter = 0;      // holds the index to the seq in the pattern
  unique_seqs = 0;      // keeps track on the number of unique sequences
  need_postprocessing = false;
  sequence = NULL;
  logcumback = NULL;
  seq_ids = rbtree_create(rbtree_strcasecmp,rbtree_strcpy,free,rbtree_intcpy,free);
  while (read_one_fasta(alph, fasta_file, options.max_seq_length, &sequence)) {
    ++seq_loading_num;
    seq_name = get_seq_name(sequence);
    seq_len = get_seq_length(sequence);
    scan_len = (options.last != 0 ? options.last : seq_len);
    // red-black trees are only required if duplicates should be combined
    if (options.combine_duplicates){
      //lookup seq id and create new entry if required, return sequence index
      seq_node = rbtree_lookup(seq_ids, get_seq_name(sequence), true, &created);
      if (created) { // assign it a loading number
        rbtree_set(seq_ids, seq_node, &unique_seqs);
        seq_counter = unique_seqs;
        ++unique_seqs;
      } else {
        seq_counter = *((int*)rbnode_get(seq_node));
      }
    }
          
    //
    // Set up sequence-dependent background model and compute
    // log cumulative probability of sequence.
    // This needs the sequence in raw format.
    //
    if (options.sdbg_order >= 0)
      logcumback = log_cumulative_background(alph, options.sdbg_order, sequence);

    // Index the sequence, throwing away the raw format and ambiguous characters
    index_sequence(sequence, alph, SEQ_NOAMBIG);

    // Get the GC content of the sequence if binning p-values by GC
    // and store it in the sequence object.
    if (options.num_gc_bins > 1) {
      ARRAY_T *freqs = get_sequence_freqs(sequence, alph);
      set_total_gc_sequence(sequence, get_array_item(y1, freqs) + get_array_item(y2, freqs)); // f(C) + f(G)
      free_array(freqs);                        // clean up
    } else {
      set_total_gc_sequence(sequence, -1);      // flag ignore
    }

    // Scan with motifs.
    for (i = 0; i < arraylst_size(motifs); i++) {
      pattern = get_cisml_patterns(cisml)[i];
      combo = (MOTIF_AND_PSSM_T*)arraylst_get(i, motifs);
      if (verbosity >= HIGHER_VERBOSE) {
        fprintf(stderr, "Scanning %s sequence with length %d "
            "abbreviated to %d with motif %s with length %d.\n",
            seq_name, seq_len, scan_len, 
            get_motif_id(combo->motif), get_motif_length(combo->motif));
      }
      SCANNED_SEQUENCE_T* scanned_seq = NULL;
      if (!options.combine_duplicates || get_pattern_num_scanned_sequences(pattern) <= seq_counter) {
        // Create a scanned_sequence record and save it in the pattern.
        scanned_seq = allocate_scanned_sequence(seq_name, seq_name, pattern);
        set_scanned_sequence_length(scanned_seq, scan_len);
      } else {
        // get existing sequence record
        scanned_seq = get_pattern_scanned_sequences(pattern)[seq_counter];
        set_scanned_sequence_length(scanned_seq, max(scan_len, get_scanned_sequence_length(scanned_seq)));
      }
      
      // check if scanned component of sequence has sufficient length for the motif
      if (scan_len < get_motif_length(combo->motif)) {
        // set score to zero and p-value to 1 if not set yet
        if(!has_scanned_sequence_score(scanned_seq)){
          set_scanned_sequence_score(scanned_seq, 0.0);
        }
        if(options.pvalues && !has_scanned_sequence_pvalue(scanned_seq)){
          set_scanned_sequence_pvalue(scanned_seq, 1.0);
        } 
        add_scanned_sequence_scanned_position(scanned_seq); 
        if (get_scanned_sequence_num_scanned_positions(scanned_seq) > 0L) {
          need_postprocessing = true;
        }
        if (verbosity >= HIGH_VERBOSE) {
          fprintf(stderr, "%s too short for motif %s. Score set to 0.\n",
              seq_name, get_motif_id(combo->motif));
        }
      } else {
        // scan the sequence using average/maximum motif affinity
        ama_sequence_scan(alph, sequence, logcumback, combo->pssm_pair,
            options.scoring, options.pvalues, options.last, scanned_seq,
            &need_postprocessing);
      }
    } // All motifs scanned

    free_seq(sequence);
    if (options.sdbg_order >= 0) myfree(logcumback);

  } // read sequences

  fclose(fasta_file);
  if (verbosity >= HIGH_VERBOSE) fprintf(stderr, "(%d) sequences read in.\n", seq_loading_num);
  if (verbosity >= NORMAL_VERBOSE) fprintf(stderr, "Finished          \n");

        
  // if any sequence identifier was multiple times in the sequence set  then
  // postprocess of the data is required
  if (need_postprocessing || options.normalize_scores) {
    post_process(cisml, motifs, options.normalize_scores);
  }
        
  // output results
  if (options.output_format == DIRECTORY_FORMAT) {
    if (create_output_directory(options.out_dir, options.clobber, verbosity > QUIET_VERBOSE)) {
      // only warn in higher verbose modes
      fprintf(stderr, "failed to create output directory `%s' or already exists\n", options.out_dir);
      exit(1);
    }
    path = make_path_to_file(options.out_dir, text_filename);
    //FIXME check for errors: MEME doesn't either and we at least know we have a good directory
    text_output = fopen(path, "w");
    free(path);
    path = make_path_to_file(options.out_dir, cisml_filename);
    //FIXME check for errors
    cisml_output = fopen(path, "w");
    free(path);
    print_cisml(cisml_output, cisml, true, NULL, false);
    print_score(cisml, text_output);
    fclose(cisml_output);
    fclose(text_output);
  } else if (options.output_format == GFF_FORMAT) {
    print_score(cisml, stdout);
  } else if (options.output_format == CISML_FORMAT) {
    print_cisml(stdout, cisml, true, NULL, false);
  } else {
    die("Output format invalid!\n");
  }

  //
  // Clean up.
  //
  rbtree_destroy(seq_ids);
  arraylst_destroy(motif_and_pssm_destroy, motifs);
  free_cisml(cisml);
  rbtree_destroy(options.selected_motifs);
  alph_release(alph);
        
  // measure time
  if (verbosity >= NORMAL_VERBOSE) { // starting time
    c1 = clock();
    fprintf(stderr, "cycles (CPU);            %ld cycles\n", (long) c1);
    fprintf(stderr, "elapsed CPU time:        %f seconds\n", (float) (c1-c0) / CLOCKS_PER_SEC);
  }
  return 0;
}
示例#26
0
    static int
    parse_document(
        fs::path const& filein_
      , fs::path const& fileout_
      , fs::path const& xinclude_base_
      , int indent
      , int linewidth
      , bool pretty_print)
    {
        string_stream buffer;
        id_manager ids;

        int result = 0;

        try {
            actions actor(filein_, xinclude_base_, buffer, ids);
            set_macros(actor);

            if (actor.error_count == 0) {
                actor.current_file = load(filein_); // Throws load_error

                parse_file(actor);

                if(actor.error_count) {
                    detail::outerr()
                        << "Error count: " << actor.error_count << ".\n";
                }
            }

            result = actor.error_count ? 1 : 0;
        }
        catch (load_error& e) {
            detail::outerr(filein_) << detail::utf8(e.what()) << std::endl;
            result = 1;
        }

        if (result == 0)
        {
            std::string stage2 = ids.replace_placeholders(buffer.str());

            fs::ofstream fileout(fileout_);

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error opening output file "
                    << fileout_
                    << std::endl;

                return 1;
            }

            if (pretty_print)
            {
                try
                {
                    fileout << post_process(stage2, indent, linewidth);
                }
                catch (quickbook::post_process_failure&)
                {
                    // fallback!
                    ::quickbook::detail::outerr()
                        << "Post Processing Failed."
                        << std::endl;
                    fileout << stage2;
                    return 1;
                }
            }
            else
            {
                fileout << stage2;
            }

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error writing to output file "
                    << fileout_
                    << std::endl;

                return 1;
            }
        }

        return result;
    }
示例#27
0
decision_proceduret::resultt smt1_dect::dec_solve()
{
  // SMT1 is really not incremental
  assert(!dec_solve_was_called);
  dec_solve_was_called=true;

  post_process();

  // this closes the SMT benchmark
  smt1_prop.finalize();
  temp_out.close();

  temp_result_filename=
    get_temporary_file("smt1_dec_result_", "");

  std::string command;

  switch(solver)
  {
  case CVC3:
    command = "cvc3 +model -lang smtlib -output-lang smtlib "
            + temp_out_filename
            + " > "
            + temp_result_filename;
    break;

  case BOOLECTOR:
    // –rwl0 disables rewriting, which makes things slower,
    // but in return values for arrays appear
    command = "boolector -rwl0 --smt "
            + temp_out_filename
            + " -fm --output "
            + temp_result_filename;
    break;

  case OPENSMT:
    command = "todo "
            + temp_out_filename
            + " > "
            + temp_result_filename;
    break;

  case YICES:
    command = "yices -smt -e "
            + temp_out_filename
            + " > "
            + temp_result_filename;
    break;

  case MATHSAT:
    command = "mathsat -model -input=smt"
              " < "+temp_out_filename
            + " > "+temp_result_filename;
    break;

  case Z3:
    command = "z3 -m "
            + temp_out_filename
            + " > "
            + temp_result_filename;
    break;

  default:
    assert(false);
  }

  #if defined(__LINUX__) || defined(__APPLE__)
  command+=" 2>&1";
  #endif

  system(command.c_str());

  std::ifstream in(temp_result_filename.c_str());

  switch(solver)
  {
  case BOOLECTOR:
    return read_result_boolector(in);

  case CVC3:
    return read_result_cvc3(in);

  case OPENSMT:
    return read_result_opensmt(in);

  case YICES:
    return read_result_yices(in);

  case MATHSAT:
    return read_result_mathsat(in);

  case Z3:
    return read_result_z3(in);

  default:
    assert(false);
  }
}
int main(int argc, char **argv)
{
    FILE    *fp, *fp2;
    char    testName[32] = "PHI_TRANSFER_KEEP_NOAL_IN";
    int     micNum, tid;
    unsigned int i, j, size, localSize, NLOOP = NLOOP_PHI_MAX, NLOOP_PHI;
    unsigned int smin = MIN_PHI_SIZE, smed = MED_PHI_SIZE, smax = MAX_PHI_SIZE;
    double  *f0, *f0_noal, *f1, *f1_noal;
    double timeMin, tStart, tElapsed[NREPS];
    double tScale = USEC, bwScale = MB;
    double overhead, threshold_lo, threshold_hi;
    double tMin, tMax, tAvg, stdDev, bwMax, bwMin, bwAvg, bwDev;
    double UsedMem, localMax, msgBytes;
    double tMsg[NREPS], bwMsg[NREPS];

    // Identify number of MIC devices
    micNum = _Offload_number_of_devices();
    if( micNum == 0 ) fatalError( "No Xeon Phi devices found. Test Aborted." );

    // Check for user defined limits
    checkEnvPHI( &NLOOP, &smin, &smed, &smax );
    if( micNum == 1 ) UsedMem = (double)smax*sizeof(double);
    if( micNum == 2 ) UsedMem = (double)smax*2.0*sizeof(double);

    // Allocate and initialize test array
    srand( SEED );
    f0 = doubleVector( smax+1 );
    // This array is unaligned by exactly 8 bytes
    f0_noal = &f0[1];

    // Check timer overhead in seconds
    timerTest( &overhead, &threshold_lo, &threshold_hi );

    // Open output files and write headers
    fp  = fopen( "mic0_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic0_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup processor with a large size exchange
    // Since we will be reusing we want to make sure this exchange uses smax
    #pragma offload_transfer target(mic:0) in( f0_noal : length(smax) ALLOC KEEP )
    // Test is current NLOOP is enough to capture fastest test cases
    tStart = benchTimer();
    for(j = 0; j < NLOOP; j++){
        #pragma offload_transfer target(mic:0) in( f0_noal : length(smin) REUSE KEEP )
    }
    timeMin = benchTimer() - tStart;
    resetInnerLoop( timeMin, threshold_lo, &NLOOP );
    // Let's save this info in case we have more than one Phi device
    NLOOP_PHI = NLOOP;

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    localSize = smin;
    localMax  = 0.0;
    for( size = smin; size <= smax; size = size*2 ){

        // Copy array to Phi (read/write test)
        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                #pragma offload_transfer target(mic:0) in( f0_noal : length(size) REUSE KEEP )
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    if( micNum == 2 ){

    // Allocate and initialize test array for second Phi coprocessor (mic:1)
    f1 = doubleVector(smax+1);
    f1_noal = &f1[1];

    // Open output files and write headers
    fp  = fopen( "mic1_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic1_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup processor with a large size exchange
    // Since we will be reusing we want to make sure this exchanges uses smax
    #pragma offload_transfer target(mic:1) in( f1_noal : length(smax) ALLOC KEEP )
    // Reset innermost loop to safe value and local quantities to defaults
    NLOOP = NLOOP_PHI;
    localSize = smin;
    localMax  = 0.0;

   //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        // Copy array to Phi (read/write test)
        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                #pragma offload_transfer target(mic:1) in( f1_noal : length(size) REUSE KEEP )
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    //------- TESTING SIMULTANEOUS DATA TRANSFER TO BOTH PHI DEVICES ------

    // Open output files and write headers
    fp  = fopen( "mic0+1_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic0+1_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    // Warmup processor with a medium size exchange
    #pragma offload_transfer target(mic:0) in( f0_noal : length(smed) REUSE KEEP )
    #pragma offload_transfer target(mic:1) in( f1_noal : length(smed) REUSE KEEP )
    // Reset innermost loop to safe value and local quantities to defaults
    NLOOP = NLOOP_PHI;
    localSize = smin;
    localMax  = 0.0;

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            #pragma omp parallel private(j,tid) num_threads(2)
            {
                tid = omp_get_thread_num();
                if( tid == 0 ){
                    for(j = 0; j < NLOOP; j++){
                        #pragma offload_transfer target(mic:0) in( f0_noal : length(size) REUSE KEEP )
                    }
                }
                if( tid == 1 ){
                    for(j = 0; j < NLOOP; j++){
                        #pragma offload_transfer target(mic:1) in( f1_noal : length(size) REUSE KEEP )
                    }
                }
            }
            tElapsed[i] = 0.5*( benchTimer() - tStart );
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    }

    free( f0 );
    if( micNum == 2 ) free( f1 );
    return 0;
}
示例#29
0
int main(int argc, char* argv[])
{
  // Check arguments
  if (argc < 3) {
    std::cerr << "Usage: shallow_water NODES_FILE TRIS_FILE\n";
    exit(1);
  }

  MeshType mesh;
  // HW4B: Need node_type before this can be used!
#if 1
  std::vector<typename MeshType::node_type> mesh_node;
#endif

  // Read all Points and add them to the Mesh
  std::ifstream nodes_file(argv[1]);
  Point p;
  while (CS207::getline_parsed(nodes_file, p)) {
    // HW4B: Need to implement add_node before this can be used!
#if 1
    mesh_node.push_back(mesh.add_node(p));
#endif
  }

  // Read all mesh triangles and add them to the Mesh
  std::ifstream tris_file(argv[2]);
  std::array<int,3> t;
  while (CS207::getline_parsed(tris_file, t)) {
    // HW4B: Need to implement add_triangle before this can be used!
#if 1
    mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]);
#endif
  }

  // Print out the stats
  std::cout << mesh.num_nodes() << " "
            << mesh.num_edges() << " "
            << mesh.num_triangles() << std::endl;

  // HW4B Initialization
  // Set the initial conditions based off third argument
  // Perform any needed precomputation
  std::pair<double, double> value_pair;
  if ((*argv[3]) == '0') {
      std::cout << "Pebble Ripple" << std::endl;
      value_pair = PebbleRipple()(mesh);
  } else if ((*argv[3]) == '1') {
      std::cout << "Sharp Wave" << std::endl;
      value_pair = SharpWave()(mesh);
  } else {
      std::cout << "Dam Break" << std::endl;
      value_pair = DamBreak()(mesh);
  }
  
  double max_height = value_pair.first;
  double min_edge_length = value_pair.second;

  // Launch the SDLViewer
  CS207::SDLViewer viewer;
  viewer.launch();

  // HW4B: Need to define Mesh::node_type and node/edge iterator
  // before these can be used!
#if 1
  auto node_map = viewer.empty_node_map(mesh);
  viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                   CS207::DefaultColor(), NodePosition(), node_map);
  viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map);
#endif
  viewer.center_view();
  // CFL stability condition requires dt <= dx / max|velocity|
  // For the shallow water equations with u = v = 0 initial conditions
  //   we can compute the minimum edge length and maximum original water height
  //   to set the time-step
  // Compute the minimum edge length and maximum water height for computing dt
#if 1
  double dt = 0.25 * min_edge_length / (sqrt(grav * max_height));
#else
  // Placeholder!! Delete me when min_edge_length and max_height can be computed!
  double dt = 0.1;
#endif
  double t_start = 0;
  double t_end = 5;

  // Preconstruct a Flux functor
  EdgeFluxCalculator f;

  // Begin the time stepping
  for (double t = t_start; t < t_end; t += dt) {
    // Step forward in time with forward Euler
    hyperbolic_step(mesh, f, t, dt);
    // Update node values with triangle-averaged values
    post_process(mesh);
    
    // Update the viewer with new node positions
#if 1
    // Update viewer with nodes' new positions
    viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                     CoolColor(), NodePosition(), node_map);
#endif
    viewer.set_label(t);

    // These lines slow down the animation for small meshes.
    // Feel free to remove them or tweak the constants.
    if (mesh.num_nodes() < 100)
      CS207::sleep(0.05);
  }

  return 0;
}
示例#30
0
文件: api.c 项目: mclumd/Alfred
void linkage_post_process(Linkage linkage, Postprocessor * postprocessor) {
    int N_sublinkages = linkage_get_num_sublinkages(linkage);
    Parse_Options opts = linkage->opts;
    Sentence sent = linkage->sent;
    Sublinkage * subl;
    PP_node * pp;
    int i, j, k;
    D_type_list * d;

    for (i=0; i<N_sublinkages; ++i) {
	
	subl = &linkage->sublinkage[i];
        if (subl->pp_info != NULL) {
	    for (j=0; j<subl->num_links; ++j) {
		exfree_pp_info(subl->pp_info[j]);
	    }
	    post_process_free_data(&subl->pp_data);
	    exfree(subl->pp_info, sizeof(PP_info)*subl->num_links);
	}
	subl->pp_info = (PP_info *) exalloc(sizeof(PP_info)*subl->num_links);
	for (j=0; j<subl->num_links; ++j) {
	    subl->pp_info[j].num_domains = 0;
	    subl->pp_info[j].domain_name = NULL;
	}
	if (subl->violation != NULL) {
	    exfree(subl->violation, sizeof(char)*(strlen(subl->violation)+1));
	    subl->violation = NULL;
	}

        if (linkage->info.improper_fat_linkage) {
            pp = NULL;
        } else {
            pp = post_process(postprocessor, opts, sent, subl, FALSE);
	    /* This can return NULL, for example if there is no
	       post-processor */
        }

	if (pp == NULL) {
	    for (j=0; j<subl->num_links; ++j) {
		subl->pp_info[j].num_domains = 0;
		subl->pp_info[j].domain_name = NULL;
	    }
	}
	else {
	    for (j=0; j<subl->num_links; ++j) {
		k=0;
		for (d = pp->d_type_array[j]; d!=NULL; d=d->next) k++;
		subl->pp_info[j].num_domains = k;
		if (k > 0) {
		    subl->pp_info[j].domain_name = (char **) exalloc(sizeof(char *)*k);
		}
		k = 0;
		for (d = pp->d_type_array[j]; d!=NULL; d=d->next) {
		    subl->pp_info[j].domain_name[k] = (char *) exalloc(sizeof(char)*2);
		    sprintf(subl->pp_info[j].domain_name[k], "%c", d->type);
		    k++;
		}
	    }
	    subl->pp_data = postprocessor->pp_data;
	    if (pp->violation != NULL) {
		subl->violation = 
		    (char *) exalloc(sizeof(char)*(strlen(pp->violation)+1));
		strcpy(subl->violation, pp->violation);
	    }
	}
    }
    post_process_close_sentence(postprocessor);
}