Exemplo n.º 1
0
int
main ( int argc, char *argv[] )
{
	size_t i, j, x, y;
	double step = 0.0;
	double **data = NULL;
	som_network_t *net = NULL;

	data = (double **) alloca ( INPUTS * sizeof ( double* ));

	for ( i=0, step = 0.0; i < INPUTS; ++i, step += 0.1 )
	{
		data[i] = (double *) alloca ( VECTORS * sizeof ( double ));

		for ( j=0; j < VECTORS; ++j )
		{
			data[i][j] = step;
		}
	}

	start_timer();

	net = som_network_new ( INPUTS, OUT_ROWS, OUT_COLS );

	if ( !net )
	{
		printf( "ERROR: som_network_new failed.\n" );
		return 1;
	}

	print_timing( "Network Creation" );

	som_init_weights ( net, data, INPUTS );
	som_train ( net, data, VECTORS, TRAIN_STEPS );

	print_timing( "Network Training" );

	for ( i=0; i < INPUTS; ++i )
	{
		som_set_inputs ( net, data[i] );
		som_get_best_neuron_coordinates ( net, &x, &y );
	//	printf ( "best coordinates [%u]: %u,%u\n", i, x, y );
	}

	print_timing( "Input Recognition" );

	som_network_destroy ( net );

	print_timing( "Network Destruction" );
}			
Exemplo n.º 2
0
static void remap_data(int index, ft_data *ftd){
  msg_tag *mtag;
  char *temp;
  int i;
  double dtime = start_timing();

  temp = (char *)malloc(sites_on_node*ftd->size);
  if(temp==NULL){
    printf("remap_data: No room\n");
    terminate(1);
  }

  mtag = start_gather_field(ftd->data, ftd->size, index, EVENANDODD,
			    gen_pt[0]);
  wait_gather(mtag);

  /* First copy gathered data to temporary */
  for(i = 0; i < sites_on_node; i++)
    memcpy(temp + ftd->size*i, gen_pt[0][i], ftd->size);

  cleanup_gather(mtag);

  /* Then copy temp back to field */
  memcpy((char *)ftd->data, temp, sites_on_node*ftd->size);

  free(temp);

  print_timing(dtime, "REMAP FFTW remap");
}
Exemplo n.º 3
0
ft_data *create_ft_data(complex *src, int size){
  char myname[] = "create_ft_data";
  ft_data *ftd;
  int ncmp;
  double dtime = start_timing();

  ftd = (ft_data *)malloc(sizeof(ft_data));
  if(ftd == NULL){
    printf("%s: No room\n", myname);
    terminate(1);
  }

  ncmp = size/sizeof(complex);
  ftd->size = ncmp*sizeof(fftw_complex);
  ftd->dir = MILC_DIR;
  ftd->data 
    = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*sites_on_node*ncmp);
  ftd->tmp 
    = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*sites_on_node*ncmp);

  if(ftd->data == NULL || ftd->tmp == NULL){
    printf("%s: no room\n",myname);
    terminate(1);
  }
  /* Copy data in */
  ft_copy_from_milc(ftd->data, src, size);

  print_timing(dtime, "REMAP FFTW copy MILC");
  return ftd;
}
Exemplo n.º 4
0
void fourier_ftdata( ft_data *ftd, int isign ){

  double dtime = start_timing();

  if(isign == 1)
    fftw_execute(fwd_plan[ftd->dir]);
  else
    fftw_execute(bck_plan[ftd->dir]);

  print_timing(dtime, "FFTW transform");
  dtime = start_timing();

  /* Copy the result from "tmp" back to "data" */

  memcpy((char *)ftd->data, (char *)ftd->tmp, ftd->size*sites_on_node);
  print_timing(dtime, "REMAP FFTW copy back");
}
Exemplo n.º 5
0
static void* check_updates_worker(void* arg){
    timing_info timing;
    reset_timing(&timing);

    while(!stop){
        start_timing(&timing);

        if(!updated && push_commit){
            if(push_commit){
                pthread_mutex_lock(&commit_mutex);

                if(push_result_shell(push_commit, NULL)){
                    puts("Failed to push coin, reseting.");

                    pthread_mutex_lock(&update_mutex);

                    fetch_updates();
                    updated = 1;

                    pthread_mutex_unlock(&update_mutex);
                } else {
                    puts("Earned it!");
                }
                push_commit = NULL;

                pthread_mutex_unlock(&commit_mutex);
            } else {
                if(check_updates()){
                    pthread_mutex_lock(&update_mutex);
                    updated = 1;
                    pthread_mutex_unlock(&update_mutex);
                }
            }
            time_point(&timing);
            print_timing(&timing);
        } else {
            skip_point(&timing);
            usleep(10);
        }
    }

    puts("Update thread ending");

    pthread_exit(NULL);
}
Exemplo n.º 6
0
static void ft_make_maps(ft_layout *ftl[], int key[], int ndim){

  int dir, dirold;
  double dtime = start_timing();

  dirold = MILC_DIR;  /* Start from MILC layout */
  for(dir = 0; dir < ndim; dir++){
    if(key[dir] != 0){
      ft_make_map(dirold, dir);
      dirold = dir;
    }
  }
  /* End with the MILC layout */
  dir = MILC_DIR;
  ft_make_map(dirold, dir);

  print_timing(dtime, "make FFTW gathers");
}
Exemplo n.º 7
0
void make_fftw_plans(int size, ft_data *ftd){
  int ncmp;
  int rank, howmany, istride, idist, ostride, odist;
  int n[1], inembed[1], onembed[1];
  int nxfm;
  unsigned flags;
  int dir;
  double dtime = start_timing();

  flags = FFTW_ESTIMATE;  /* Could try FFTW_MEASURE */
  rank = 1;
  /* Number of complex values in a 4D site datum */
  ncmp = size/sizeof(complex);
  idist = odist = 1;

  for(dir = 0; dir < NDIM; dir++)
    if(layout[dir] != NULL){
      
      nxfm = layout[dir]->nxfm;
      
      /* The FT dimension */
      n[0] = inembed[0] = onembed[0] = nxfm;
      
      /* Number of contiguous complex values per 1D coordinate being
	 transformed */
      howmany = (sites_on_node*ncmp)/nxfm;
      ostride = istride = howmany;
      
      fwd_plan[dir] = 
	fftw_plan_many_dft(rank, n, howmany, 
			   ftd->data, inembed, istride, idist, 
			   ftd->tmp, onembed, ostride, odist, 
			   FFTW_FORWARD, flags);
      bck_plan[dir] = 
	fftw_plan_many_dft(rank, n, howmany, 
			   ftd->data, inembed, istride, idist, 
			   ftd->tmp, onembed, ostride, odist, 
			   FFTW_BACKWARD, flags);
    }

  print_timing(dtime, "make FFTW plans");
}
Exemplo n.º 8
0
void ft_create_layouts(ft_layout *ftl[], ft_layout **ft_milc, 
		       int ndim, int dims[], int key[]){
  int dir;
  int dtime = start_timing();

  /* Set up the FT layout structure for each dir needed */
  /* We don't remake the FT layout if it already exists, i.e.  the
     pointer is nonnull.  This provision allows a user to call
     setup_restrict_fourier multiple times without risking a memory
     leak */
  for(dir = 0; dir < ndim; dir++)
    if(ftl[dir] == NULL && key[dir] != 0){
      ftl[dir] = ft_create_ft_layout(ndim);
      ft_setup_layout(ftl[dir]->nsquares, ftl[dir]->squaresize,
		      ftl[dir]->dirp, ndim, dims, dir);
      ftl[dir]->node_number = ft_node_number;
      ftl[dir]->node_index = ft_node_index;
      ftl[dir]->get_coords = ft_get_coords;
      ftl[dir]->nxfm = dims[dir];
    }

  /* Set up the MILC layout structure */
  if(*ft_milc == NULL){
    *ft_milc = ft_create_ft_layout(ndim);
    /* Copy in the current MILC hypercubic layout dimensions and
       function pointers */
    ft_fill_milc_layout((*ft_milc)->nsquares, (*ft_milc)->squaresize, 
			(*ft_milc)->dirp, ndim, dims);
    (*ft_milc)->node_number = milc_node_number;
    (*ft_milc)->node_index = milc_node_index;
    (*ft_milc)->get_coords = milc_get_coords;
    (*ft_milc)->nxfm = 0;  /* We don't run transforms with the MILC layout */
  }

  print_timing(dtime, "create FFT layouts");
}
Exemplo n.º 9
0
/**
 * Main function which selects the process to be a master or a worker
 * based on MPI myid.
 *
 * @param argc Number of arguments.
 * @param argv Pointer to the argument pointers.
 * @return     0 on success.
 */
int main(int argc, char **argv)
{
    int myid, numprocs, i;
    int err = -1;
    struct test_params_s test_params;
    struct mpe_events_s mpe_events;
    struct frag_preresult_s **query_frag_preresult_matrix = NULL;

    memset(&test_params, 0, sizeof(struct test_params_s));
    MPI_Init(&argc, &argv);
#ifdef HAVE_MPE    
    MPI_Pcontrol(0);
#endif

    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);

    init_mpe_events(&mpe_events);
#ifdef HAVE_MPE
    if (myid == MASTER_NODE)
    {
	init_mpe_describe_state(&mpe_events);
    }
#endif
    if (myid == MASTER_NODE)
    {
	err = parse_args(argc, argv, &test_params);
	if (err >= 0)
	    print_settings(&test_params, numprocs);
	if (test_params.output_file != NULL)
	    MPI_File_delete(test_params.output_file, MPI_INFO_NULL);
	if (numprocs < 2)
	{
	    fprintf(stderr, "Must use at least 2  processes.\n");
	    err = -1;
	}
    }

    MPI_Bcast(&err, 1, MPI_INT, MASTER_NODE, MPI_COMM_WORLD);
    /* Quit if the parse_args failed */
    if (err != 0)
    {
	MPI_Finalize();
	return 0;
    }

    /* Master precalculates all the results for the queries and
     * reads in the database histogram parameters */
    if (myid == MASTER_NODE)
    {
	if ((query_frag_preresult_matrix = (struct frag_preresult_s **) 
	     malloc(test_params.query_count * 
		    sizeof(struct frag_preresult_s *))) == NULL)
	{
	    custom_debug(
		MASTER_ERR, 
		"M:malloc query_frag_preresult_matrix of size %d failed\n",
		test_params.query_count * sizeof(struct frag_preresult_s *));
	    return -1;
	}
	for (i = 0; i < test_params.query_count; i++)
	{
	    if ((query_frag_preresult_matrix[i] = (struct frag_preresult_s *)
		 malloc(test_params.total_frags * 
			sizeof(struct frag_preresult_s))) == NULL)
	    {
		custom_debug(
		    MASTER_ERR,
		    "M:malloc query_frag_preresult_matrix[%d] "
		    "of size %d failed\n", i,
		    test_params.total_frags *
		    sizeof(struct frag_preresult_s));
		return -1;
	    }
	    memset(query_frag_preresult_matrix[i], 0, 
		   test_params.total_frags * sizeof(struct frag_preresult_s));
	}
	precalculate_results(&test_params, query_frag_preresult_matrix);
	test_params.query_frag_preresult_matrix = query_frag_preresult_matrix;
	if (test_params.query_params_file != NULL)
	{
	    read_hist_params(&test_params, QUERY);
#if 0
	    print_hist_params(&test_params);
#endif
	}
	if (test_params.db_params_file != NULL)
	{
	    read_hist_params(&test_params, DATABASE);
#if 0
	    print_hist_params(&test_params);
#endif
	}
    }

    MPI_Barrier(MPI_COMM_WORLD);
#ifdef HAVE_MPE
    MPI_Pcontrol(1);
#endif

    /* Divide up into either a Master or Worker */
    mpe_events.total_time = MPI_Wtime();
    if (myid == 0)
    {
	err = master(myid,
		     numprocs,
		     &mpe_events,
		     &test_params);
	if (err != 0)
	    custom_debug(MASTER_ERR, "master failed\n");
	else
	    custom_debug(MASTER, "master (proc %d) reached last barrier\n",
			 myid);
    }
    else
    {
	err = worker(myid,
		     numprocs,
		     &mpe_events,
		     &test_params);
	if (err != 0)
	    custom_debug(WORKER_ERR, "worker failed\n");
	else
	    custom_debug(WORKER, "worker (proc %d) reached last barrier\n",
			 myid);
    }

    custom_MPE_Log_event(mpe_events.sync_start,
			 0, NULL, &mpe_events);
    MPI_Barrier(MPI_COMM_WORLD);
    custom_MPE_Log_event(mpe_events.sync_end,
			 0, NULL, &mpe_events);
    MPI_Pcontrol(0);    
    mpe_events.total_time = MPI_Wtime() - mpe_events.total_time;
#if 0
    print_timing(myid, &mpe_events);
#endif
    MPI_Barrier(MPI_COMM_WORLD);
    timing_reduce(myid, numprocs, &mpe_events);
    
    /* Clean up precomputed results and file */
    if (myid == MASTER_NODE)
    {
	if (test_params.query_params_file != NULL)
	{
	    free(test_params.query_params_file);
	    free(test_params.query_hist_list);
	}
	if (test_params.db_params_file != NULL)
	{
	    free(test_params.db_params_file);
	    free(test_params.db_hist_list);
	}

	MPI_File_delete(test_params.output_file, MPI_INFO_NULL);
	for (i = 0; i < test_params.query_count; i++)
	{
	    free(query_frag_preresult_matrix[i]);
	}
	free(query_frag_preresult_matrix);
    }

    MPI_Info_free(test_params.info_p);
    free(test_params.info_p);
    free(test_params.output_file);
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
    return 0;
}
Exemplo n.º 10
0
int main (int argc, char **argv) {
    git_index *index = NULL;
    pthread_t updateThread, hashThread;
    int rc, difficulty;
    void *status;
    hash_args args;
    timing_info timing;
    git_oid curr_commit;

    reset_timing(&timing);

    pthread_mutex_init(&commit_mutex, NULL);
    pthread_mutex_init(&update_mutex, NULL);
    push_commit = NULL;

    difficulty = init_args(&args);
    init_git(&index);

    init_hasher(difficulty);

    check_updates();
    reset_hard();

    puts("Starting update thread");
    rc = pthread_create(&updateThread, NULL, check_updates_worker, NULL);
    if (rc){
        printf("ERROR creating update thread %d\n", rc);
        exit(-1);
    }

    signal (SIGINT, int_handler);

    while(!stop){
        start_timing(&timing);

        args.found = 0;

        time_point(&timing);

        pthread_mutex_lock(&commit_mutex);
        pthread_mutex_lock(&update_mutex);
        if(updated){
            reset_hard();
            updated = 0;
            push_commit = NULL;
        }
        pthread_mutex_unlock(&update_mutex);
        pthread_mutex_unlock(&commit_mutex);

        time_point(&timing);

        puts("Preparing index");
        prepare_index(index, args.msg);
        time_point(&timing);

        puts("Starting brute force thread");
        rc = pthread_create(&hashThread, NULL, force_hash, &args);

        time_point(&timing);

        if (rc){
            printf("ERROR creating hash thread %d\n", rc);
            stop = 1;
        } else {
            pthread_join(hashThread, &status);
        }

        time_point(&timing);

        if(!stop && !updated && args.found){
            puts("Found one!");

            while(push_commit){
                usleep(10);
            }

            time_point(&timing);

            if(!stop && !updated){
                pthread_mutex_lock(&commit_mutex);

                commit_result(args.msg, &curr_commit);
                push_commit = &curr_commit;

                pthread_mutex_unlock(&commit_mutex);
            }
        } else {
            puts("Reset while looking for a hash");
            time_point(&timing);
        }

        time_point(&timing);
        print_timing(&timing);
    }

    pthread_join(updateThread, &status);

    free_hasher();
    free(args.msg);

    git_index_free(index);
    git_repository_free(repo);

    git_threads_shutdown();

    return 0;
}
Exemplo n.º 11
0
 void print_timing(double warmDeltaT, double sampleDeltaT) {
   print_timing(warmDeltaT, sampleDeltaT, _sample_stream, '#');
   print_timing(warmDeltaT, sampleDeltaT, _diagnostic_stream, '#');
   print_timing(warmDeltaT, sampleDeltaT, &std::cout);
 }
Exemplo n.º 12
0
 void output_timing(double warmDeltaT, double sampleDeltaT) {
   print_timing(warmDeltaT, sampleDeltaT, psample_stream_, std::string("# "));
   print_timing(warmDeltaT, sampleDeltaT, pdiagnostic_stream_, std::string("# "));
 }