Exemple #1
0
int main( int argc , char * argv[] )

{
  THD_3dim_dataset * new_dset = NULL;      /* output bucket dataset */
  

  /*----- Identify software -----*/
#if 0
  printf ("\n\n");
  printf ("Program:          %s \n", PROGRAM_NAME);
  printf ("Author:           %s \n", PROGRAM_AUTHOR); 
  printf ("Initial Release:  %s \n", PROGRAM_INITIAL);
  printf ("Latest Revision:  %s \n", PROGRAM_LATEST);
  printf ("\n");
#endif

  PRINT_VERSION("3dFDR") ; AUTHOR(PROGRAM_AUTHOR); mainENTRY("3dFDR main") ; machdep() ;

  /*----- Initialize program:  get all operator inputs; 
    create mask for voxels above mask threshold -----*/
  initialize_program (argc, argv);


  if (FDR_input1D_filename != NULL)
    {
      /*----- Process list of p-values -----*/
      process_1ddata ();
    }
  else
    {
      /*----- Process 3d dataset -----*/
      new_dset = process_dataset ();

      /*----- Output the results as a bucket dataset -----*/
      output_results (new_dset);
    }
  
  exit(0) ;
}
Exemple #2
0
void Main::assign_cluster_props () {
  // Funciton that assigns cluster properties.

  for(int i = 0; i < clusters.size(); i++) {
    /* Remove duplicate members */
    clusters[i].unique();
    /* Assign properties */
    clusters[i].assign_props();
    /* Assign signal-to-noise using background density */
    clusters[i].assign_sn(fabs(spline_bg(clusters[i].z)));
  }

  /* Sort clusters by number of members */
  std::sort(clusters.begin(), clusters.end());
  std::reverse(clusters.begin(), clusters.end());

  /* Rename clusters */
  for(int i = 0; i < clusters.size(); i++) 
    clusters[i].rename(i + 1);

  output_results();

}
Exemple #3
0
int test() 
{
  struct timeval timeout, now;
  fd_set sel_read, sel_except, sel_write;
  int i;
  
  {
    /* get server information */
    struct hostent *he;
    he = gethostbyname(machine);
    if (!he) err("gethostbyname");
    server.sin_family      = he->h_addrtype;
    server.sin_port        = htons(port);
    server.sin_addr.s_addr = ((unsigned long *)(he->h_addr_list[0]))[0];
  }

  con = malloc(concurrency*sizeof(struct connection));
  memset(con,0,concurrency*sizeof(struct connection));
  
  stats = malloc(requests * sizeof(struct data));

  FD_ZERO(&readbits);
  FD_ZERO(&writebits);

  /* setup request */
  sprintf(request,"GET %s HTTP/1.0\r\nUser-Agent: ZeusBench/1.0\r\n"
	  "%sHost: %s\r\nAccept: */*\r\n\r\n", file, 
	  keepalive?"Connection: Keep-Alive\r\n":"", machine );
    
  reqlen = strlen(request);

  /* ok - lets start */
  gettimeofday(&start,0);

  /* initialise lots of requests */
  for(i=0; i<concurrency; i++) start_connect(&con[i]);

  while(done<requests) {
    int n;
    /* setup bit arrays */
    memcpy(&sel_except, &readbits, sizeof(readbits));
    memcpy(&sel_read, &readbits, sizeof(readbits));
    memcpy(&sel_write, &writebits, sizeof(readbits));

    /* check for time limit expiry */
    gettimeofday(&now,0);
    if(tlimit && timedif(now,start) > (tlimit*1000)) {
      requests=done;   /* so stats are correct */
      output_results();
    }

    /* Timeout of 30 seconds. */
    timeout.tv_sec=30; timeout.tv_usec=0;
    n=select(256, &sel_read, &sel_write, &sel_except, &timeout);
    if(!n) {
      printf("\nServer timed out\n\n");
      exit(1);
    }
    if(n<1) err("select");

    for(i=0; i<concurrency; i++) {
      int s = con[i].fd;
      if(FD_ISSET(s, &sel_except)) {
	bad++; 
	err_except++;
	start_connect(&con[i]);
	continue;
      }
      if(FD_ISSET(s, &sel_read)) read_connection(&con[i]);
      if(FD_ISSET(s, &sel_write)) write_request(&con[i]);
    }
    if(done>=requests) output_results();
  }
  return 0;
}
int main(int argc, char *argv[]) {

    // CLI options
    static struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {"file", required_argument, 0, 'f'},
        {"disp", no_argument, 0, 'd'},
        {"metaheuristic", required_argument, 0, 'g'},
        {"population-based", required_argument, 0, 'P'},
        {"meta-optional-arg", required_argument, 0, 'm'},
        {"tweaker-optional-arg", required_argument, 0, 'o'},
        {"tweaker", required_argument, 0, 'x'},
        {"results", required_argument, 0, 'r'},
        {"debugging", no_argument, 0, 'a'},
        {0, 0, 0, 0}
    };

    // Parser of CLI
    int opt = 0, option_index, runs;
    bool flag_h = false; 
    bool flag_f = false; 
    bool flag_d = false; 
    bool flag_g = false; 
    bool flag_m = false; 
    bool flag_o = false; 
    bool flag_n = false;
    bool flag_x = false;
    bool flag_r = false;
    bool flag_t = false;
    bool flag_a = false;
    bool flag_P = false;
    memset(metaheuristic_optional_arg, 0, sizeof(metaheuristic_optional_arg));
    memset(tweaker_optional_arg, 0, sizeof(tweaker_optional_arg));
    memset(population_optional_arg, 0, sizeof(population_optional_arg));

    // We need these three things
    std::string file_name, metaheuristic_str, tweaker_str, out_fn, population_str;

    while (1) {
        opt = getopt_long(argc, argv, "dhf:g:m:o:x:n:r:t:p:P:", long_options, &option_index);
        if (opt == -1) break;
        opt = char(opt);

        switch (opt) {
            case 0  : break;
            case 'h': flag_h = true; print_help(); break;
            case 'f': flag_f = true; file_name = optarg; break;
            case 'g': flag_g = true; metaheuristic_str = optarg; break; 
            case 'm': metaheuristic_optional_arg[moa_counter++] = atoi(optarg); 
                      break;
            case 'o': tweaker_optional_arg[toa_counter++] = atoi(optarg); 
                      break;
            case 'x': flag_x = true; tweaker_str = optarg; break;
            case 'n': flag_n = true; runs = atoi(optarg); break;
            case 'r': flag_r = true; out_fn = optarg; break;
            case 'd': flag_d = true; break;
            case 't': flag_t = true; file_name = optarg; break;
            case 'a': flag_a = true;  break;
            case 'P': flag_P = true; population_str = optarg; break;
            case 'p': population_optional_arg[poa_counter++] = atoi(optarg); 
                      break;
            case '?': break;
        }
    }

    if (flag_h) return 0; // Print help and exit

    // Checking and exit in case of error
    if (! flag_g and ! flag_d) error_("You have to specify a metaheuristic"); 
    if (  flag_f and   flag_t) error_("You cannot use -f and -t together");
    if (! flag_x and ! flag_d) error_("You have to specify a tweaker");
    if ((! flag_f and ! flag_d) and (!flag_t)) error_("You have to specify a file");  
    if (! flag_n and ! flag_d) runs = 1;

    Metaheuristic *metaheuristic = choose_metaheuristic(metaheuristic_str, 
                                    metaheuristic_optional_arg, 
                                    moa_counter);
    if (!metaheuristic) {
        std::cerr << "Error: No metaheuristic by that name." << std::endl;
        exit(1);
    }
    Tweaker *tweaker = choose_tweaker(tweaker_str,
                                      tweaker_optional_arg,
                                      toa_counter);
    if (!tweaker) {
        std::cerr << "Error: No tweaker by that name." << std::endl;
        exit(1);
    }

    metaheuristic->setTweaker(tweaker); // Setting tweaker

    if (flag_P) {
        Metaheuristic *ls = metaheuristic;
        metaheuristic = choose_population(population_str, ls, 
                                          population_optional_arg, poa_counter);
        metaheuristic->setTweaker(tweaker);
        // Hard coded parameters since others since these seem to work fine
        metaheuristic->set_no_change_best(30);
        metaheuristic->set_ite_limit(1000);
    }


    if (flag_f) {
        IS::Dataset dataset = load_data_basic(file_name);
        // Initial random solution
        IS::Solution solution(dataset.size());
        // solution.generateRandom(); 
        metaheuristic->optimize(dataset, solution);
        if (flag_a) debug_print(dataset, solution);
    } else if (flag_t) {
        vps datasets;
        load_data_tenfold(file_name, datasets);
        results res = run_tenfold(datasets, metaheuristic, runs);
        output_results(res, metaheuristic, flag_r, out_fn);
    }

    if (flag_d) {
        IS::Dataset dataset = load_data_basic(file_name);
        print_dispersions(dataset);
        return 0;
    }
   
    return 0;
}
Exemple #5
0
void mm_tst_cases(int NTRIALS, int Ndim, int Mdim, int Pdim, 
              TYPE* A, TYPE* B, TYPE* C, 
              void (*mm_func)(int, int, int, TYPE *, TYPE *, TYPE *))
{
   int    nerr, itrials;
   double err,  errsq, mflops;
   double start_time, run_time;
   double min_t, max_t, ave_t;
   TYPE *Cref;

   Cref = (TYPE *) malloc (Ndim * Mdim * sizeof(TYPE));

   /* Initialize matrices */

   init_const_matrix (Ndim, Mdim, Pdim, A, B, Cref);

   printf("\n constant matrices  %d %d %d\n", Ndim, Mdim, Pdim);
   nerr = 0; min_t = BIG;  max_t = SMALL; ave_t = (double) 0.0;
   for (itrials = 0; itrials<NTRIALS; itrials++){

      mm_clear(Ndim, Mdim, C);
      start_time = omp_get_wtime(); 

      mm_func(Ndim, Mdim, Pdim, A, B, C);

      run_time = omp_get_wtime() - start_time;
  
      errsq = errsqr(Ndim, Mdim, C, Cref);
      if (errsq > TOL) nerr++;
      if(run_time < min_t) min_t = run_time;
      if(run_time > max_t) max_t = run_time;
      ave_t += run_time;
   }

   ave_t = ave_t/(double)NTRIALS;
   output_results(Ndim, Mdim, Pdim, nerr, ave_t, min_t, max_t);

   init_progression_matrix (Ndim, Mdim, Pdim, A, B, Cref);

#ifdef DEBUG
   printf(" A progression Matrix input\n");
   mm_print(Ndim, Pdim, A);

   printf(" B progression Matrix input\n");
   mm_print(Pdim, Mdim, B);

   printf(" C Reference Matrix\n");
   mm_print(Ndim, Mdim, Cref);
#endif

   printf("\n progression matrices  %d %d %d\n", Ndim, Mdim, Pdim);
   nerr = 0; min_t = BIG;  max_t = SMALL; ave_t = (double) 0.0;
   for (itrials = 0; itrials<NTRIALS; itrials++){

      mm_clear(Ndim, Mdim, C);
      start_time = omp_get_wtime(); 

      mm_func(Ndim, Mdim, Pdim, A, B, C);

      run_time = omp_get_wtime() - start_time;

#ifdef DEBUG
   printf(" C progression Matrix result\n");
   mm_print(Ndim, Mdim, C);
#endif
      errsq = errsqr(Ndim, Mdim, C, Cref);
      if (errsq > TOL) nerr++;
      if(run_time < min_t) min_t = run_time;
      if(run_time > max_t) max_t = run_time;
      ave_t += run_time;
   }

   ave_t = ave_t/(double)NTRIALS;
   output_results(Ndim, Mdim, Pdim, nerr, ave_t, min_t, max_t);
}
Exemple #6
0
int main(int argc, char *argv[])
{
	int choice = atoi(argv[1]);
	bool isPairEnd = false;

	if (choice) {
	
		char *kmerPath = argv[2];
		char *refPath = argv[3];

		char *taxonomyNodesPath = argv[4];
		char *giTaxidPath = argv[5];
		char *dirPath = argv[6];
		

		//vector<uint64_t> fKmer;
		_kmer = (uint8_t) atoi(argv[7]); 
		string  bwt_s;
		vector<uint32_t> nKmerTaxonID;	
		
		fprintf(stderr,"start preprocessing......\n");
		
	
		uint64_t hash_index_size = (uint64_t)1 <<((PREINDEXLEN<<1) + 1);
		
		uint64_t *hash_index = new uint64_t[hash_index_size]();

		preprocess(refPath, kmerPath, taxonomyNodesPath, giTaxidPath,  bwt_s, nKmerTaxonID, hash_index);

		fprintf(stderr,"writing index....\n");
		//char *dirPath = ".";
		//
		bwt bt(bwt_s.c_str(), bwt_s.length(),hash_index);

		bt.bwt_init();

		bt.write_info(dirPath, nKmerTaxonID);
		//uint64_t sp,ep;	
		//bt.exactMatch("GCTTCGCTGTTATTGGCACCAATTGGATCAC",31, sp,ep);
	} else {
	
		char *readPath;
	
		
		char *taxonomyNodesPath;
		
		char * dirPath;
		
		char *readPath_s;	
		
		
		fprintf(stderr,"%d", argc);	
		if (argc > 7 ) {
			isPairEnd = true;
		
			readPath = argv[2];
		
			readPath_s = argv[3];	
			
			taxonomyNodesPath = argv[4];
			
			dirPath = argv[5];
			_kmer = (uint8_t) atoi(argv[6]);
			
			_interval = atoi(argv[7]);
	
		} else {
		
			readPath = argv[2];
			
			taxonomyNodesPath = argv[3];
			
			
			dirPath = argv[4];
			
			_kmer = (uint8_t) atoi(argv[5]);
			
			_interval = atoi(argv[6]);
		
		}


		--_kmer;
		
		bwt bt(_kmer);
		
		fprintf(stderr,"loading index\n");

		bt.load_info(dirPath);
		
		taxonTree(taxonomyNodesPath);
		//map<uint32_t, uint32_t>::iterator it = taxonomyTree.begin();
		//while (it!=taxonomyTree.end()) {
		//	cout<<it->first<<"\t"<<it->second<<endl;

		//	++it;
		//}
		//cout<<taxonomyTree.size()<<endl;
		fprintf(stderr,"classifying...\n");
		
		gzFile fp;
		
		//uint32_t *nKmerTaxonID = bt.taxonIDTab;	
		
		fp = gzopen(readPath, "r");

		if (!fp) return FILE_OPEN_ERROR;

		kstream_t *_fp = ks_init(fp);

		kseq_t *seqs = (kseq_t *) calloc(N_NEEDED, sizeof(kseq_t));

		if (!seqs) return MEM_ALLOCATE_ERROR;
		//
		//parameters for pair-end reads
		gzFile fp_s;
		kstream_t *_fp_s;
		kseq_t *seqs_s;

		if (isPairEnd) {
		
			fp_s = gzopen(readPath_s, "r");

			if (!fp_s) return FILE_OPEN_ERROR;

			_fp_s  = ks_init(fp_s);

			seqs_s = (kseq_t *) calloc(N_NEEDED, sizeof(kseq_t));
			
			if (!seqs_s) return MEM_ALLOCATE_ERROR;
		
		
		}

		if (!seqs) return MEM_ALLOCATE_ERROR;
		
		cly_r *results = (cly_r *)calloc(2 * N_NEEDED, sizeof(cly_r));




  		struct timeval tv1, tv2;
		
		int n_seqs;
		total_sequences = 0;
		gettimeofday(&tv1,NULL);
		if (isPairEnd) {
		
			while ((n_seqs = read_reads(_fp, seqs, N_NEEDED) )> 0 && read_reads(_fp_s, seqs_s, N_NEEDED)) {
				
				classify_seq(seqs, n_seqs , bt, results, 0);
				classify_seq(seqs_s, n_seqs, bt, results, 1);
				output_results(results, n_seqs, isPairEnd);
				total_sequences += n_seqs;
			}	
		
		
		} else {
		
			while ((n_seqs = read_reads(_fp, seqs, N_NEEDED) )> 0) {
			
				classify_seq(seqs, n_seqs , bt, results, 0);
				output_results(results, n_seqs, isPairEnd);
				total_sequences += n_seqs;

			}	
		
		}	
		gettimeofday(&tv2,NULL);
		report_stats(tv1,tv2);

		//fprintf(stderr,"%f seconds\n",((float)t)/CLOCKS_PER_SEC);
		if (results) free(results);
		if (seqs) free(seqs);

	}
	
	//char *st;
	
	//uint32_t *uts;

	//uint64_t z;
	//load_index(dirPath, st, uts, &z );		
	//cerr<<<<endl;
	//fprintf(stderr,"%s\n",st);
	
	//uint64_t sp, ep;

	//bwt b(st, uts, z);
	
	//b.bwt_init();
	//char *read = "GGCT";
	//cout<<b.exactMatch(read,4,sp,ep )<<endl;
	//cout<<sp<<"\t"<<ep<<endl;	
	//read reads file
	//output(kmerValue, kmerInfo, _2kmers);
	

	return NORMAL_EXIT;

}
int
main(void)
{
  Simulation_Run_Ptr simulation_run;
  Simulation_Run_Data_Ptr data;

  /*
   * Declare and initialize our random number generator seeds defined in
   * simparameters.h
   */

  unsigned RANDOM_SEEDS[] = {RANDOM_SEED_LIST, 0};
  unsigned random_seed;
  int j=0;

  /* 
   * Loop for each random number generator seed, doing a separate
   * simulation_run run for each.
   */

  while ((random_seed = RANDOM_SEEDS[j++]) != 0) {

    simulation_run = simulation_run_new(); /* Create a new simulation run. */

    /*
     * Create a Simulation_Run_Data object. This will hold all of our user
     * defined data (declared in main.h). Set the simulation_run data pointer
     * to our new object.
     */

    data = (Simulation_Run_Data_Ptr) xmalloc(sizeof(Simulation_Run_Data));
    simulation_run_set_data(simulation_run, (void*) data);

    /* 
     * Initialize the simulation_run data variables, declared in main.h.
     */
    
    data->blip_counter = 0;
    data->arrival_count = 0;
    data->number_of_packets_processed = 0;
    data->accumulated_delay = 0.0;
    data->random_seed = random_seed;
 
    /* 
     * Create the packet buffer and transmission link, declared in main.h.
     */

    data->buffer = fifoqueue_new();
    data->link   = server_new();

    /* 
     * Set the random number generator seed for this run.
     */

    random_generator_initialize(random_seed);

    /* 
     * Schedule the initial packet arrival for the current clock time (= 0).
     */

    schedule_packet_arrival_event(simulation_run, 
				  simulation_run_get_time(simulation_run));

    /* 
     * Execute events until we are finished. 
     */

    while(data->number_of_packets_processed < RUNLENGTH) {
      simulation_run_execute_event(simulation_run);
    }

    /*
     * Output results and clean up after ourselves.
     */

    output_results(simulation_run);
    cleanup_memory(simulation_run);
  }

  getchar();   /* Pause before finishing. */
  return 0;
}
Exemple #8
0
int main(int argc, char *argv[])
{
  int ID;
  char line[MAX_LINE];
  FILE *tmp;
  FILE *output;

  //Argument 1: Welcoming port
  if (argc < 2)
  {
    printf("No port specified\n");
    exit(-1);
  }

  /* Create a welcome socket at the specified port */
  welcome_socket = ServerSocket_new(atoi(argv[1]));
  if (welcome_socket < 0)
  {
    printf("Failed new server socket\n");
    exit(-1);
  }

  /* Open a connect socket through the welcom socket*/
  connect_socket = ServerSocket_accept(welcome_socket);
  if (connect_socket < 0)
  {
    printf("Failed connect socket\n");
    exit(-1);
  }

  Socket_close(welcome_socket);  //Close the welcome socket as it is unused

  pid_t childPID;
  char *argcv[MAXARGSIZE];
  int child_status;

  /* Run until exited*/
  while ( 1 )
  {
    ID = (int)getpid();                    // Get PID of the Current Process
    sprintf(filename, "tmp%d", ID);        // Make file name from the current pid
    tmp = freopen(filename, "w", stdout);  // Redirect stdout to the tmp file

    read_line(line);
  
    childPID = fork();  //Child Process to read from client and execute
    if (childPID < 0)
    {
      printf("Fork error\n");
      exit(-1);
    }

    if (childPID == 0)  //Child process
    {
      tokenize(line, argv);  //Tokenize the input line into arguments
      errno = 0;
      // Check if the file name is valid
      if (execvp(*argv, argv) == -1 ) //Run the command in the arguments list
      {
	printf("Execvp error: %d\n", errno);
        exit(-1);
      }      
    }
    else if (childPID > 0)
    {
      int flag = 0;

      //Wait until the child process finishes
      if (waitpid(-1, &child_status, 0) == -1) {
	printf("Server: wait error\n");
      }
      //Check signals for child process
      if (WIFSIGNALED(child_status)) {
	printf("Server: WIFSIGNALED ERROR: %d\n", WTERMSIG(child_status));
      }
      else if (WIFSTOPPED(child_status)) {
	printf("Server: WIFSTOPPED ERROR: %d\n", WSTOPSIG(child_status));
      }
 
      fclose(tmp);  //Close the redirected temp file

      output_results();  //Ouput thte reuslts back into socket
    }
  }
}
Exemple #9
0
/*
 * Function:    run_test
 * Purpose:     Inner loop call to actually run the I/O test.
 * Return:      Nothing
 * Programmer:  Bill Wendling, 18. December 2001
 * Modifications:
 */
static int
run_test(iotype iot, parameters parms, struct options *opts)
{
    results         res;
    register int    i, ret_value = SUCCESS;
    off_t           raw_size;
    minmax         *write_sys_mm_table=NULL;
    minmax         *write_mm_table=NULL;
    minmax         *write_gross_mm_table=NULL;
    minmax         *write_raw_mm_table=NULL;
    minmax         *read_sys_mm_table=NULL;
    minmax         *read_mm_table=NULL;
    minmax         *read_gross_mm_table=NULL;
    minmax         *read_raw_mm_table=NULL;
    minmax          write_sys_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          write_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          write_gross_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          write_raw_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          read_sys_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          read_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          read_gross_mm = {0.0F, 0.0F, 0.0F, 0};
    minmax          read_raw_mm = {0.0F, 0.0F, 0.0F, 0};

    raw_size = (off_t)parms.num_bytes;
    parms.io_type = iot;
    print_indent(2);
    output_report("IO API = ");

    switch (iot) {
        case POSIXIO:
            output_report("POSIX\n");
            break;
        case HDF5:
            output_report("HDF5\n");
            break;
        default:
            /* unknown request */
            HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)iot);
            HDassert(0 && "Unknown IO tpe");
            break;
    }

    /* allocate space for tables minmax and that it is sufficient */
    /* to initialize all elements to zeros by calloc.             */
    write_sys_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
    write_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
    write_gross_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
    write_raw_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));

    if (!parms.h5_write_only) {
        read_sys_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
        read_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
        read_gross_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
        read_raw_mm_table = (minmax *)calloc((size_t)parms.num_iters , sizeof(minmax));
    }

    /* Do IO iteration times, collecting statistics each time */
    for (i = 0; i < parms.num_iters; ++i) {
        double t;

        do_sio(parms, &res);

        /* gather all of the "sys write" times */
        t = get_time(res.timers, HDF5_MPI_WRITE);
        get_minmax(&write_sys_mm, t);

        write_sys_mm_table[i] = write_sys_mm;

        /* gather all of the "write" times */
        t = get_time(res.timers, HDF5_FINE_WRITE_FIXED_DIMS);
        get_minmax(&write_mm, t);

        write_mm_table[i] = write_mm;

        /* gather all of the "write" times from open to close */
        t = get_time(res.timers, HDF5_GROSS_WRITE_FIXED_DIMS);
        get_minmax(&write_gross_mm, t);

        write_gross_mm_table[i] = write_gross_mm;

        /* gather all of the raw "write" times */
        t = get_time(res.timers, HDF5_RAW_WRITE_FIXED_DIMS);
        get_minmax(&write_raw_mm, t);

        write_raw_mm_table[i] = write_raw_mm;

        if (!parms.h5_write_only) {
            /* gather all of the "mpi read" times */
            t = get_time(res.timers, HDF5_MPI_READ);
            get_minmax(&read_sys_mm, t);

            read_sys_mm_table[i] = read_sys_mm;

            /* gather all of the "read" times */
            t = get_time(res.timers, HDF5_FINE_READ_FIXED_DIMS);
            get_minmax(&read_mm, t);

            read_mm_table[i] = read_mm;

            /* gather all of the "read" times from open to close */
            t = get_time(res.timers, HDF5_GROSS_READ_FIXED_DIMS);
            get_minmax(&read_gross_mm, t);

            read_gross_mm_table[i] = read_gross_mm;

            /* gather all of the raw "read" times */
            t = get_time(res.timers, HDF5_RAW_READ_FIXED_DIMS);
            get_minmax(&read_raw_mm, t);

            read_raw_mm_table[i] = read_gross_mm;
        }
        io_time_destroy(res.timers);
    }

    /*
     * Show various statistics
     */
    /* Write statistics	*/
    /* Print the raw data throughput if desired */
    if (opts->print_raw) {
        /* accumulate and output the max, min, and average "raw write" times */
        if (sio_debug_level >= 3) {
            /* output all of the times for all iterations */
            print_indent(3);
            output_report("Raw Data Write details:\n");
            output_all_info(write_raw_mm_table, parms.num_iters, 4);
        }

        output_results(opts,"Raw Data Write",write_raw_mm_table,parms.num_iters,raw_size);
    } /* end if */

    /* show sys write statics */
#if 0
    if (sio_debug_level >= 3) {
        /* output all of the times for all iterations */
        print_indent(3);
        output_report("MPI Write details:\n");
        output_all_info(write_sys_mm_table, parms.num_iters, 4);
    }
#endif
    /* We don't currently output the MPI write results */

    /* accumulate and output the max, min, and average "write" times */
    if (sio_debug_level >= 3) {
        /* output all of the times for all iterations */
        print_indent(3);
        output_report("Write details:\n");
        output_all_info(write_mm_table, parms.num_iters, 4);
    }

    output_results(opts,"Write",write_mm_table,parms.num_iters,raw_size);

    /* accumulate and output the max, min, and average "gross write" times */
    if (sio_debug_level >= 3) {
        /* output all of the times for all iterations */
        print_indent(3);
        output_report("Write Open-Close details:\n");
        output_all_info(write_gross_mm_table, parms.num_iters, 4);
    }

    output_results(opts,"Write Open-Close",write_gross_mm_table,parms.num_iters,raw_size);

    if (!parms.h5_write_only) {
        /* Read statistics	*/
        /* Print the raw data throughput if desired */
        if (opts->print_raw) {
            /* accumulate and output the max, min, and average "raw read" times */
            if (sio_debug_level >= 3) {
                /* output all of the times for all iterations */
                print_indent(3);
                output_report("Raw Data Read details:\n");
                output_all_info(read_raw_mm_table, parms.num_iters, 4);
            }

            output_results(opts, "Raw Data Read", read_raw_mm_table,
                           parms.num_iters, raw_size);
        } /* end if */

        /* show mpi read statics */
#if 0
        if (sio_debug_level >= 3) {
            /* output all of the times for all iterations */
            print_indent(3);
            output_report("MPI Read details:\n");
            output_all_info(read_sys_mm_table, parms.num_iters, 4);
        }
#endif
        /* We don't currently output the MPI read results */

        /* accumulate and output the max, min, and average "read" times */
        if (sio_debug_level >= 3) {
            /* output all of the times for all iterations */
            print_indent(3);
            output_report("Read details:\n");
            output_all_info(read_mm_table, parms.num_iters, 4);
        }

        output_results(opts, "Read", read_mm_table, parms.num_iters, raw_size);

        /* accumulate and output the max, min, and average "gross read" times */
        if (sio_debug_level >= 3) {
            /* output all of the times for all iterations */
            print_indent(3);
            output_report("Read Open-Close details:\n");
            output_all_info(read_gross_mm_table, parms.num_iters, 4);
        }

        output_results(opts, "Read Open-Close", read_gross_mm_table,
                       parms.num_iters, raw_size);
    }

    /* clean up our mess */
    free(write_sys_mm_table);
    free(write_mm_table);
    free(write_gross_mm_table);
    free(write_raw_mm_table);

    if (!parms.h5_write_only) {
        free(read_sys_mm_table);
        free(read_mm_table);
        free(read_gross_mm_table);
        free(read_raw_mm_table);
    }

    return ret_value;
}
void MPS_Favored::create(size_t num_dim_in, bool is_periodic, double r, Search_Factory::Search_Type search_type, bool all_searches_global, bool perm_ghosts)
{
  std::cout << std::endl << "Starting favored-spokes d:" << num_dim_in << " r:" << r << std::endl;

  // run time
  _run_time.start_clock();
  _setup_time.start_clock();
  
  //===============
  // Parameters
  //===============

  // Passed in:
  // num_dim
  // is_periodic
  // r

  // _do_central_beta = true;

  // spokes go from 1r to 3.8r
  const double anchor_dist = 1.;
  const double spoke_extent = 3.8;
  
  const bool do_wheels = false;

  const bool do_greedy_pass = true; // should the algorithm throw darts greedily?
  bool greedy_pass = false; // is the current set of dart throws greedy
  const size_t greedy_max_misses = 6;
  
  // num_successive_misses = 6; from orig
  _max_misses = 6; // 6 or 12?

  assert( greedy_max_misses <= _max_misses ); // change loop control if we want a larger value for greedy misses

  //===============
  // Setup
  //===============

  double max_search_distance = (spoke_extent + 1.1) * r; // .1 is a safety factor
  _influence_neighborhood = spoke_extent+1.5; // for reporting histogram
  truncate_influence_neighborhood( r );

  MPS::create(num_dim_in, is_periodic, r, max_search_distance, search_type, 0, perm_ghosts, all_searches_global);

  // Global_Container &all_spheres = *(ghosts ? new Ghost_Global_Container(*ghosts) : new Global_Container(*_spheres));

  // Search Structures

  Spoke_Length sl(anchor_dist, spoke_extent, r);

  bool dart_is_from_wheel = false;
  Wheel_Stats wheel_stats;
  bool covered_sphere(false);

  _nested_searches.clear();
  _nested_searches.reserve(3);

  _nested_searches._searches.push_back( _global_search );

  // subset of global space
  const double spoke_nbr_dist = (spoke_extent + 1.) * r;
  Search_Structure *spoke_nbr = Search_Factory::new_search( search_type, _spheres, all_searches_global, spoke_nbr_dist, 1., 0.);
  //  if (!all_searches_global) // always
  {
    _nested_searches._searches.push_back( spoke_nbr );
    _nested_searches._distances.push_back( spoke_nbr_dist );
  }

  // subset of spoke_nbr
  const double anchor_nbr_dist = (anchor_dist + 1.) * r;
  Search_Structure *anchor_nbr = Search_Factory::new_search( search_type, _spheres, all_searches_global, anchor_nbr_dist, 1., 0.);
  //  if (!all_searches_global) // always
  {
    _nested_searches._searches.push_back( anchor_nbr );
    _nested_searches._distances.push_back( anchor_nbr_dist );
  }
  
  double *dart = _sd->new_sphere();
  double *u = _sd->new_sphere();

  //===============
  // debug
  //===============
  _loop_count = 0;
  _outer_loop_count = 0;
  Point_Tool::_verification_level = 0;
  
  bool draw_report_solid_disks = false;
  bool draw_report_shaded_disks = false;

  if (/* DISABLES CODE */ (0))
  {
    draw_report_solid_disks = false;
    draw_report_shaded_disks = false;
    _draw_solid_disks = (num_dim_in == 2);
    _draw_shaded_disks = (num_dim_in == 2);
    _draw_solid_disks = false;
    _draw_shaded_disks = false;
    _do_beta = (num_dim_in < 7);
  }
  // silent settings, for do_central_beta
  if (1)
  {
    draw_report_solid_disks = false;
    draw_report_shaded_disks = false;
    _draw_solid_disks = false;
    _draw_shaded_disks = false;
    _do_beta = false;
    _draw_histogram = false;
  }

  
  _setup_time.collect_stats();
  _main_time.start_clock();

  // first disk
  create_center_sphere( dart, r );
  Global_Container front_spheres(*_spheres);
  bool failed(false);

  // report on progess periodically
  std::cout << "Starting Favored Spokes! " << std::endl;
  size_t next_report(0);
  report(1, next_report);
  next_report = 1000 / num_dim();

 
  // for all front spheres
  for ( _front_disk = front_spheres.first(); !failed && _front_disk != front_spheres.bad_sphere_index(); _front_disk = front_spheres.next() )
  {

    _outer_loop_count = _loop_count;
    if (/* DISABLES CODE */ (0) && (_outer_loop_count == 61476))
    {
      std::cout << "outer, loop count " << _loop_count << " debug me!" << std::endl;
      std::cout << "_front_disk: " << _front_disk << " ";
      _spheres->_pt.print_sphere( (*_spheres)[_front_disk] );
      std::cout << std::endl;
      Point_Tool::_verification_level = 1; //0, 1, 2
    }

    
    // ====================================
    // advance the front
    // ====================================
    if (skip_front_disk())
      continue;

    advance_front();
    greedy_pass = do_greedy_pass;

    // quit if we've produced the requested number of layers around the central sphere
    if (reached_layer_limit())
      break;

    // throw spoke darts
    do 
    {

      ++_loop_count;

      // debug
      if (/* DISABLES CODE */ (0) && ( _loop_count == 61478 || (*_spheres)[0] == 0) )
      {
        std::cout << "inner, loop count " << _loop_count << " debug me!" << std::endl;
        Point_Tool::_verification_level = 1;
      }
      
      // ====================================
      // pick anchor point
      // ====================================

      sl.A = r;      
      bool valid_dart = _sd->generate_dart(dart, u, sl.A, _c, anchor_nbr,
                                    do_wheels, &dart_is_from_wheel, &wheel_stats, &covered_sphere );
            // if the whole sphere is covered, we know all future throws will fail, too
      if (covered_sphere)
        _quit_early = true;


      // =====================================================
      // Trim spoke through uncovered anchor
      // =====================================================
      if (valid_dart)
      {
        sl.reset(r);

        _sd->trim_by_domain( _c, u, sl.A_2, &_domain ); // does nothing if periodic
        assert(sl.A_2 >= sl.A_1);
        
        spoke_nbr->trim_line_anchored(_c, u, r, sl.A, sl.A_1, sl.A_2);

        // greedy?
        if (greedy_pass && sl.was_trimmed())
        {
          valid_dart = false;
        }
        
        // skip short spokes
        else 
          valid_dart = spoke_is_long( sl, r );
      }
      
      // ==========================================================
      // place sample point on non-empty trimmed dart
      // ==========================================================
      if (valid_dart)
      {
        // pick a sample point from the interval [A_1, A, A_2], but non-uniformly
        // store it in "dart"
        double dx = _sd->sample_from_spoke(sl, r, _sample_start_min, _sample_start_max, _mid_1, _mid_2, _top, _mid_frac);

        // double dx = _rng->random_uniform(sl.A_1, sl.A_2);
        _sd->axpy(dart, dx, u, _c);
      }
      
      // =====
      // debug plot disks
      // =====
      if (/* DISABLES CODE */ (0))
      {
        if (_loop_count > next_report)
        {
          Darts_IO io;
          if (draw_report_solid_disks)
          {
            io.plot_vertices_2d_allblack( io.loop_string( _loop_count, "B"), _spheres, &_domain, 1. );
          }
          if (draw_report_shaded_disks)
          {
            if (valid_dart)
              io.plot_vertices_2d_dart(  io.loop_string(_loop_count), _spheres, &_domain, 1., _front_disk, dart, &sl, u);
            else
              io.plot_vertices_2d_nodart( io.loop_string(_loop_count), _spheres, &_domain, 1., _front_disk );
          }
        }
      }
      
      // ===================================================================
      // add the dart to the pool of spheres, and subsequent local searches
      // ===================================================================
      if (valid_dart)
      {
        failed = failed || !create_new_sphere( dart );
      }

      // ====================================
      // miss
      // ====================================
      if (!valid_dart)
      {
        ++_misses;

        // greedy pass
        if ( greedy_pass && _misses >= greedy_max_misses )
        {
          greedy_pass = false;
          _misses = 0;
        }
      }

      // debug
//      if ( _ghosts->num_ghosts() > 1000 )
//      {
//        std::cout << _ghosts->num_ghosts() <<  " ghosts exist" << std::endl;
//      }
      report(_loop_count, next_report);

    } while ( _misses < _max_misses && !_quit_early ); // for dart throws

  }

  // debug plots
  if (/* DISABLES CODE */ (0))
  {
    Darts_IO io;
    if (draw_report_solid_disks)
    {
      io.plot_vertices_2d_allblack( io.loop_string(_loop_count, "B"), _spheres, &_domain, 1. );
    }
    if (draw_report_shaded_disks)
    {
      io.plot_vertices_2d_nodart( io.loop_string(_loop_count), _spheres, &_domain, 1., _front_disk );
    }
  }

  winnow_disks_for_output();
  
  output_results();

  //cleanup
  _sd->delete_sphere(dart);
  _sd->delete_sphere(u);
  
  Search_Factory::delete_search( anchor_nbr);
  Search_Factory::delete_search( spoke_nbr );
  _nested_searches.clear();

}
Exemple #11
0
int main(int argc, char *argv[])
{
/* Local declarations. */
  struct Zoltan_Struct *zz = NULL;

  char  *cmd_file;
  char   cmesg[256]; /* for error messages */

  float  version;

  int    Proc, Num_Proc;
  int    iteration;
  int    error, gerror;
  int    print_output = 1;

  MESH_INFO  mesh;             /* mesh information struct */
  PARIO_INFO pio_info;
  PROB_INFO  prob;

/***************************** BEGIN EXECUTION ******************************/

  /* initialize MPI */
  MPI_Init(&argc, &argv);

#ifdef VAMPIR
  VT_initialize(&argc, &argv);
#endif

  /* get some machine information */
  MPI_Comm_rank(MPI_COMM_WORLD, &Proc);
  MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc);

  my_rank = Proc;

#ifdef HOST_LINUX
  signal(SIGSEGV, meminfo_signal_handler);
  signal(SIGINT, meminfo_signal_handler);
  signal(SIGTERM, meminfo_signal_handler);
  signal(SIGABRT, meminfo_signal_handler);
  signal(SIGFPE, meminfo_signal_handler);
#endif

#ifdef ZOLTAN_PURIFY
  printf("%d of %d ZDRIVE LAUNCH pid = %d file = %s\n", 
         Proc, Num_Proc, getpid(), argv[1]);
#endif

  /* Initialize flags */
  Test.DDirectory = 0;
  Test.Local_Parts = 0;
  Test.Fixed_Objects = 0;
  Test.Drops = 0;
  Test.RCB_Box = 0;
  Test.Multi_Callbacks = 0;
  Test.Graph_Callbacks = 1;
  Test.Hypergraph_Callbacks = 1;
  Test.Gen_Files = 0;
  Test.Null_Lists = NO_NULL_LISTS;
  Test.Dynamic_Weights = .0;
  Test.Dynamic_Graph = .0;
  Test.Vtx_Inc = 0;

  Output.Text = 1;
  Output.Gnuplot = 0;
  Output.Nemesis = 0;
  Output.Plot_Partition = 0;
  Output.Mesh_Info_File = 0;

  /* Interpret the command line */
  switch(argc)
  {
  case 1:
    cmd_file = "zdrive.inp";
    break;

  case 2:
    cmd_file = argv[1];
    break;

  default:
    fprintf(stderr, "MAIN: ERROR in command line,");
    if(Proc == 0)
    {
      fprintf(stderr, " usage:\n");
      fprintf(stderr, "\t%s [command file]", DRIVER_NAME);
    }
    exit(1);
    break;
  }

  /* initialize Zoltan */
  if ((error = Zoltan_Initialize(argc, argv, &version)) != ZOLTAN_OK) {
    sprintf(cmesg, "fatal: Zoltan_Initialize returned error code, %d", error);
    Gen_Error(0, cmesg);
    error_report(Proc);
    print_output = 0;
    goto End;
  }

  /* initialize some variables */
  initialize_mesh(&mesh, Proc);

  pio_info.dsk_list_cnt		= -1;
  pio_info.file_comp            = STANDARD;
  pio_info.num_dsk_ctrlrs	= -1;
  pio_info.pdsk_add_fact	= -1;
  pio_info.zeros		= -1;
  pio_info.file_type		= -1;
  pio_info.chunk_reader         = 0;
  pio_info.init_dist_type	= -1;
  pio_info.init_size		= ZOLTAN_ID_INVALID;
  pio_info.init_dim 		= -1;
  pio_info.init_vwgt_dim 	= -1;
  pio_info.init_dist_pins       = -1;
  pio_info.pdsk_root[0]		= '\0';
  pio_info.pdsk_subdir[0]	= '\0';
  pio_info.pexo_fname[0]	= '\0';

  prob.method[0]		= '\0';
  prob.num_params		= 0;
  prob.params			= NULL;

  /* Read in the ascii input file */
  error = gerror = 0;
  if (Proc == 0) {
    printf("\n\nReading the command file, %s\n", cmd_file);
    if (!read_cmd_file(cmd_file, &prob, &pio_info, NULL)) {
      sprintf(cmesg,"fatal: Could not read in the command file"
              " \"%s\"!\n", cmd_file);
      Gen_Error(0, cmesg);
      error_report(Proc);
      print_output = 0;
      error = 1;
    }

    if (!check_inp(&prob, &pio_info)) {
      Gen_Error(0, "fatal: Error in user specified parameters.\n");
      error_report(Proc);
      print_output = 0;
      error = 1;
    }

    print_input_info(stdout, Num_Proc, &prob, &pio_info, version);
  }

  MPI_Allreduce(&error, &gerror, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
  if (gerror) goto End;

  /* broadcast the command info to all of the processor */
  brdcst_cmd_info(Proc, &prob, &pio_info, &mesh);

  Zoltan_Set_Param(NULL, "DEBUG_MEMORY", "1");
  print_output = Output.Text;

  /*
   *  Create a Zoltan structure.
   */
  if ((zz = Zoltan_Create(MPI_COMM_WORLD)) == NULL) {
    Gen_Error(0, "fatal:  NULL returned from Zoltan_Create()\n");
    return 0;
  }

  if (!setup_zoltan(zz, Proc, &prob, &mesh, &pio_info)) {
    Gen_Error(0, "fatal: Error returned from setup_zoltan\n");
    error_report(Proc);
    print_output = 0;
    goto End;
  }

  /* srand(Proc); Different seeds on different procs. */
  srand(1);  /* Same seed everywhere. */

  if (Test.Dynamic_Weights){
    /* Set obj weight dim to 1; can be overridden by user parameter */
    Zoltan_Set_Param(zz, "OBJ_WEIGHT_DIM", "1");
  }

  /* Loop over read and balance for a number of iterations */
  /* (Useful for testing REUSE parameters in Zoltan.) */
  for (iteration = 1; iteration <= Number_Iterations; iteration++) {

    if (Proc == 0) {
      printf("Starting iteration %d\n", iteration); 
      fflush(stdout);
    }

    /*
     * now read in the mesh and element information.
     * This is the only function call to do this. Upon return,
     * the mesh struct and the elements array should be filled.
     */
    if (iteration == 1) {
      if (!read_mesh(Proc, Num_Proc, &prob, &pio_info, &mesh)) {
        Gen_Error(0, "fatal: Error returned from read_mesh\n");
        error_report(Proc);
        print_output = 0;
        goto End;
      }
      /*
       *  Create a Zoltan DD for tracking elements during repartitioning.
       */

      if (mesh.data_type == ZOLTAN_HYPERGRAPH && !build_elem_dd(&mesh)) {
        Gen_Error(0, "fatal: Error returned from build_elem_dd\n");
        error_report(Proc);
        print_output = 0;
        goto End;
      }
    }


#ifdef KDDKDD_COOL_TEST
/* KDD Cool test of changing number of partitions  */
    sprintf(cmesg, "%d", Num_Proc * iteration);
    Zoltan_Set_Param(zz, "NUM_GLOBAL_PARTS", cmesg);
#endif

    /*
     * Produce files to verify input.
     */
    if (iteration == 1) {
      if (Debug_Driver > 2) {
        if (!output_results(cmd_file,"in",Proc,Num_Proc,&prob,&pio_info,&mesh)){
          Gen_Error(0, "fatal: Error returned from output_results\n");
          error_report(Proc);
        }
        if (Output.Gnuplot)
          if (!output_gnu(cmd_file,"in",Proc,Num_Proc,&prob,&pio_info,&mesh)) {
            Gen_Error(0, "warning: Error returned from output_gnu\n");
            error_report(Proc);
          }
      }
      if (Test.Vtx_Inc<0){
        /* Read Citeseer data from file */
        FILE *fp;
        int i=0;
        if (Proc==0){
          fp = fopen("months.txt", "r");
          if (!fp)
            printf("ERROR: Couldn't open file months.txt\n");
          while (fscanf(fp, "%d", &CITESEER[i])==1){
            ++i;
          }
          fclose(fp);
        }
        MPI_Bcast (CITESEER, 200, MPI_INT, 0, MPI_COMM_WORLD);
      }
    }

    if (Test.Dynamic_Graph > 0.0){
      if (mesh.data_type == ZOLTAN_GRAPH) {
        remove_random_vertices(&mesh, iteration, Test.Dynamic_Graph); 
      }
      else{
        Gen_Error(0, "fatal: \"test dynamic graph\" only works on graphs, not hypergraphs\n");
        error_report(Proc);
        print_output = 0;
        goto End;
      }
    }

    if (Test.Vtx_Inc){
      if (mesh.data_type == ZOLTAN_HYPERGRAPH ) {
        if (Test.Vtx_Inc>0)
          mesh.visible_nvtx += Test.Vtx_Inc; /* Increment uniformly */
        else
          mesh.visible_nvtx = CITESEER[iteration-1]; /* Citeseer document matrix. */
      }
      else{
        Gen_Error(0, "fatal: \"vertex increment\" only works on hypergraphs\n");
        error_report(Proc);
        print_output = 0;
        goto End;
      }
    }

    /*
     * now run Zoltan to get a new load balance and perform
     * the migration
     */
  
#ifdef IGNORE_FIRST_ITERATION_STATS
if (iteration == 1) {
  /* Exercise partitioner once on Tbird because first run is slow. */
  /* Lee Ann suspects Tbird is loading shared libraries. */
  struct Zoltan_Struct *zzcopy;
  zzcopy = Zoltan_Copy(zz);
  /* Don't do any migration or accumulate any stats. */
  if (Proc == 0) printf("%d KDDKDD IGNORING FIRST ITERATION STATS\n", Proc);
  Zoltan_Set_Param(zzcopy, "RETURN_LISTS", "NONE");
  Zoltan_Set_Param(zzcopy, "FINAL_OUTPUT", "0");
  Zoltan_Set_Param(zzcopy, "USE_TIMERS", "0");
  if (!run_zoltan(zzcopy, Proc, &prob, &mesh, &pio_info)) {
    Gen_Error(0, "fatal: Error returned from run_zoltan\n");
    error_report(Proc);
    print_output = 0;
    goto End;
  }
  Zoltan_Destroy(&zzcopy);
}
#endif /* IGNORE_FIRST_ITERATION_STATS */
#ifdef RANDOM_DIST
 if (iteration % 2 == 0) {
   char LB_METHOD[1024];

  if (Proc == 0) printf("%d CCCC Randomizing the input\n", Proc);
   strcpy(LB_METHOD, prob.method);
   strcpy(prob.method, "RANDOM");
   Zoltan_Set_Param(zz, "LB_METHOD", "RANDOM");
   Zoltan_Set_Param(zz, "RETURN_LISTS", "ALL");
    if (!run_zoltan(zz, Proc, &prob, &mesh, &pio_info)) {
      Gen_Error(0, "fatal: Error returned from run_zoltan\n");
      error_report(Proc);
      print_output = 0;
      goto End;
    }
   Zoltan_Set_Param(zz, "RETURN_LISTS", "NONE");
   Zoltan_Set_Param(zz, "LB_METHOD", LB_METHOD);
   strcpy(prob.method, LB_METHOD);
  if (Proc == 0) printf("%d CCCC Randomizing the input -- END\n", Proc);
 }
#endif /* RANDOM_DIST */
    if (!run_zoltan(zz, Proc, &prob, &mesh, &pio_info)) {
      Gen_Error(0, "fatal: Error returned from run_zoltan\n");
      error_report(Proc);
      print_output = 0;
      goto End;
    }

    /* Reset the mesh data structure for next iteration. */
    if (iteration < Number_Iterations) {
      int i, j;
      float tmp;
      float twiddle = 0.01;
      char str[4];
      /* Perturb coordinates of mesh */
      if (mesh.data_type == ZOLTAN_GRAPH){
        for (i = 0; i < mesh.num_elems; i++) {
          for (j = 0; j < mesh.num_dims; j++) {
            /* tmp = ((float) rand())/RAND_MAX; *//* Equiv. to sjplimp's test */
            tmp = (float) (i % 10) / 10.;
            mesh.elements[i].coord[0][j] += twiddle * (2.0*tmp-1.0);
            mesh.elements[i].avg_coord[j] = mesh.elements[i].coord[0][j];
          }
        }
        /* Increase weights in some parts */
        if (Test.Dynamic_Weights){
          /* Randomly pick 10% of parts to "refine" */
          /* Note:  Assumes at least 10 parts!  */
          /* Increase vertex weight, and also edge weights? TODO */
          j = (int) ((10.0*rand())/RAND_MAX + .5);
          for (i = 0; i < mesh.num_elems; i++) {
            if ((mesh.elements[i].my_part%10) == j){
                mesh.elements[i].cpu_wgt[0] = Test.Dynamic_Weights*(1+rand()%5);
            }
          }
        }
      }
      /* change the ParMETIS Seed */
      sprintf(str, "%d", iteration);
#ifdef ZOLTAN_PARMETIS      
      Zoltan_Set_Param(zz, "PARMETIS_SEED", str);
#endif
    }

  } /* End of loop over read and balance */

  if (Proc == 0) {
    printf("FILE %s:  Total:    %e seconds in Partitioning\n", 
           cmd_file, Total_Partition_Time);
    printf("FILE %s:  Average:  %e seconds per Iteration\n", 
           cmd_file, Total_Partition_Time/Number_Iterations);
  }

End:
  Zoltan_Destroy(&zz);
  if (mesh.dd) Zoltan_DD_Destroy(&(mesh.dd));

  Zoltan_Memory_Stats();

  /*
   * output the results
   */
  if (print_output) {
    if (!output_results(cmd_file,"out",Proc,Num_Proc,&prob,&pio_info,&mesh)) {
      Gen_Error(0, "fatal: Error returned from output_results\n");
      error_report(Proc);
    }

    if (Output.Gnuplot) {
      if (!output_gnu(cmd_file,"out",Proc,Num_Proc,&prob,&pio_info,&mesh)) {
        Gen_Error(0, "warning: Error returned from output_gnu\n");
        error_report(Proc);
      }
    }
  }

  free_mesh_arrays(&mesh);
  if (prob.params != NULL) free(prob.params);
  MPI_Finalize();
  
#ifdef VAMPIR
  VT_finalize();
#endif

  return 0;
}
Exemple #12
0
int MAIN__(int argc, char** argv) {
    int num;  // number of data
    int dim;  // dimension of each data
    int nprow=4; // number of row
    int npcol=1;  // number of columnn
    int zero=0, one=1; // constant value
    int ictxt,myrow,mycol,pnum,pdim,info;
    char ifilename[LEN_FILENAME];
    char ofilename[LEN_FILENAME];

    int myproc, nprocs;
    Cblacs_pinfo(&myproc, &nprocs);
    Cblacs_setup(&myproc, &nprocs);
    Cblacs_get(-1,0,&ictxt);
    nprow = nprocs;
    npcol = 1; // fixed

    char order[] = "Row";
    Cblacs_gridinit(&ictxt, order, nprow, npcol);
    Cblacs_gridinfo(ictxt, &nprow, &npcol, &myrow, &mycol);

    if (DEBUG_MODE) {
        printf("ConTxt = %d\n", ictxt);
        printf("nprocs=%d, nprow=%d, npcol=%d\n", nprocs, nprow, npcol);
        printf("nprocs=%d, myrow=%d, mycol=%d\n", nprocs, myrow, mycol);
    }

    get_option(argc, argv, ifilename, ofilename, &num, &dim);

    // 0. cosinedist(ij) = 1 - V(i)V(j)/(Length(V(i))*Length(V(j)))

    // 1. calculate submatrix size
    int bsize = num / nprow; // blocking factor
    pnum = num / nprow;
    pdim = dim;
    if ( myrow < (num/bsize)%nprow) {
        pnum += bsize;
    }
    else if ( myrow == (num/bsize)%nprow) {
        pnum += (num % bsize);
    }
    else {
    }
    if(DEBUG_MODE)
        printf("myproc=%d: pnum=%d, pdim=%d, bsize=%d\n", myproc, pnum, pdim, bsize);

    int desc_input[9], desc_v[9], desc_ip[9], desc_n[9], desc_result[9];
    descinit_(desc_input,  &num, &dim, &num,   &dim,  &zero, &zero, &ictxt, &num,  &info);
    descinit_(desc_v,      &num, &dim, &bsize, &pdim, &zero, &zero, &ictxt, &pnum, &info);
    descinit_(desc_ip,     &num, &num, &bsize, &num,  &zero, &zero, &ictxt, &pnum, &info);
    descinit_(desc_n,      &num, &one, &bsize, &one,  &zero, &zero, &ictxt, &pnum, &info);
    descinit_(desc_result, &num, &num, &num,   &num,  &zero, &zero, &ictxt, &num,  &info);

    // 2. read input data
    double* input;
    if (myproc == 0) {
        input = (double*)malloc(sizeof(double)*num*dim);
        memset(input, 0, sizeof(double)*num*dim);
        read_data(ifilename, num, dim, input);
        printArray("input", myproc, input, num, dim);
    }

    // 3. distribute input data array
    double* V = (double*)malloc(sizeof(double)*pnum*pdim);
    memset(V, 0, sizeof(double)*pnum*pdim);
    Cpdgemr2d(num, dim, input, 1, 1, desc_input, V, 1, 1, desc_v, ictxt);
    printArray("V", myproc, V, pnum, pdim);

    // 4. InnerProduct = VV'
    double* InnerProduct = (double*)malloc(sizeof(double)*pnum*num);
    memset(InnerProduct, 0, sizeof(double)*pnum*num);
    char transa = 'N', transb = 'T';
    int m = num, n = num, k = dim;
    int lda = num, ldb = num, ldc = num;
    double alpha = 1.0f, beta = 0.0f;
    pdgemm_(&transa, &transb, &m, &n, &k, &alpha, V, &one, &one, desc_v, V, &one, &one, desc_v, &beta, InnerProduct, &one, &one, desc_ip);
    printArray("InnerProduct", myproc, InnerProduct, pnum, num);

    // 5. Norm of each vector
    double* Norm = (double*)malloc(sizeof(double)*pnum);
    for (int i = 0; i < pnum; i++) {
        int n = ((myproc*bsize)+(i/bsize)*(nprocs-1)*bsize+i)*pnum + i;
        Norm[i] = sqrt(InnerProduct[n]);
    }
    printArray("Norm", myproc, Norm, 1, pnum);

    // 6. Norm product matrix
    double* NormProduct = (double*)malloc(sizeof(double)*pnum*num);
    memset(NormProduct, 0, sizeof(double)*pnum*num);
    char uplo = 'U';
    n = num;
    alpha = 1.0f;
    int incx = 1;
    lda = num;
    pdsyr_(&uplo, &n, &alpha, Norm, &one, &one, desc_n, &incx, NormProduct, &one, &one, desc_ip);
    printArray("NormProduct", myproc, NormProduct, pnum, num);

    // 7. CosineDistance(ij) = 1-InnerProduct(ij)/NormProduct(ij)
    double* CosineDistance = (double*)malloc(sizeof(double)*pnum*num);
    memset(CosineDistance, 0, sizeof(double)*pnum*num);
    for (int j = 0; j < num; j++) {
        for (int i = 0; i < pnum; i++) {
            int n = ((myproc*bsize)+i+(i/bsize)*(nprocs-1)*bsize)*pnum+i;
            int p = i+j*pnum;
            if (p<=n) {
                CosineDistance[p] = 0.0;
            }
            else {
                CosineDistance[p] = 1 - InnerProduct[p]/NormProduct[p];
            }
        }
    }
    printArray("CosineDistance", myproc, CosineDistance, pnum, num);

    // 8. gather result
    double* result;
    if ( myproc == 0 ) {
        result = (double*)malloc(sizeof(double)*num*num);
        memset(result, 0, sizeof(double)*num*num);
    }
    Cpdgemr2d(num, num, CosineDistance, 1, 1, desc_ip, result, 1, 1, desc_result, ictxt);

    // 9. output to file
    if ( myproc == 0 ) {
        output_results(ofilename, result, num, num);
    }

    // a. cleanup memory
    free(V);
    free(InnerProduct);
    free(Norm);
    free(NormProduct);
    free(CosineDistance);
    if ( myproc == 0 ) {
        free(input);
        free(result);
    }

    blacs_exit_(&zero);

    return 0;
}
Exemple #13
0
int
main(int argc, char *argv[]) {
    int rc = 0;
    Network *N = NULL;

    time_measure_start(&GNRL_ST.total_time);

    //process input arguments and init global structure
    rc |= process_input_args(argc, argv);

    if (GNRL_ST.quiet_mode == FALSE)
        printf("mfinder Version %.2f\n\n", VERSION);


    if (rc == RC_ERR)
        at_exit(-1);

    //general initialization
    rc |= gnrl_init();
    if (rc == RC_ERR)
        at_exit(-1);

    // load network from input file
    if (GNRL_ST.quiet_mode == FALSE)
        printf("Loading Network\n");
    load_network(&G_N, input_network_fname);
    duplicate_network(G_N, &N, "real_network");

    init_random_seed();

    if (rc == RC_ERR)
        at_exit(-1);
    if (GNRL_ST.quiet_mode == FALSE)
        printf("Searching motifs size %d\nProcessing Real network...\n", GNRL_ST.mtf_sz);

    //search motifs size n in Real network
    if (GNRL_ST.dont_search_real != TRUE)
        rc |= motifs_search_real(N);
    if (rc == RC_ERR)
        at_exit(-1);

/*
    printf("RES TBL real\n");
    for (l_id = list64_get_next(RES_TBL.real, NULL); l_id != NULL;
            l_id = list64_get_next(RES_TBL.real, l_id))
    {
        printf("id: %d\ncount: %.0f\n", (int)((Motif*)l_id->p)->id,
                ((Motif*)l_id->p)->count);
    }
*/


    if (GNRL_ST.quiet_mode == FALSE)
        printf("Processing Random networks\n");
    if (GNRL_ST.rnd_net_num > 0) {
        // create random networks with same single node statisticfs as the input network
        if (GNRL_ST.r_grassberger == FALSE) {
            //use switches or stubs
            rc |= process_rand_networks(&RES_TBL, GNRL_ST.mtf_sz);
        } else {
            //use grassberger alg
            weights_arr = (double*) calloc(GNRL_ST.rnd_net_num + 1, sizeof (double));
            rc |= process_rand_networks_grassberger(&RES_TBL, GNRL_ST.mtf_sz, weights_arr);
        }
        if (rc == RC_ERR)
            at_exit(-1);
    }

    if (GNRL_ST.quiet_mode == FALSE)
        printf("Calculating Results...\n");
    if (GNRL_ST.rnd_net_num >= 0) {
        //calculate final results and dump them to the results file
        if (!GNRL_ST.r_grassberger) {
            calc_final_results(&RES_TBL, &final_res, &final_res_all, GNRL_ST.rnd_net_num);
        } else {
            //Nadav change for GRASS NEW
            calc_final_results_grassberger(&RES_TBL, FALSE, res_sub_motif, &final_res, &final_res_all, GNRL_ST.rnd_net_num, weights_arr);
        }
    }

    //calculate final results
    time_measure_stop(&GNRL_ST.total_time);
    //output results
    rc |= output_results(final_res, final_res_all);

    free_network_mem(G_N);
    free(G_N);

    final_res_free(final_res);
    final_res_free(final_res_all);

    if (GNRL_ST.r_grassberger)
        free(weights_arr);

    res_tbl_mem_free(&RES_TBL);

    if (GNRL_ST.calc_roles == TRUE) {
        free_mem_role_hash();
        free_roles_res_tbl(GNRL_ST.rnd_net_num);
        free_role_members();
    }

    if (rc == RC_ERR)
        at_exit(-1);

    exit(at_exit(rc));
}