示例#1
0
void initialize(options _opts) {
	opts = _opts;
#if !defined(_MSC_VER)
	feenableexcept (FE_DIVBYZERO);
	feenableexcept (FE_INVALID);
	feenableexcept (FE_OVERFLOW);
#endif
	grid::set_scaling_factor(opts.xscale);
	grid::set_max_level(opts.max_level);

	if (opts.problem == DWD) {
		set_problem(scf_binary);
		set_refine_test(refine_test_bibi);
	} else if (opts.problem == SOD) {
		grid::set_fgamma(7.0 / 5.0);
		gravity_on = false;
		set_problem(sod_shock_tube);
		set_refine_test (refine_sod);
		grid::set_analytic_func(sod_shock_tube);
	} else if (opts.problem == BLAST) {
		grid::set_fgamma(7.0 / 5.0);
		gravity_on = false;
		set_problem (blast_wave);
		set_refine_test (refine_blast);
	} else if (opts.problem == STAR) {
		grid::set_fgamma(5.0 / 3.0);
		set_problem(star);
		set_refine_test(refine_test_bibi);
	} else if (opts.problem == MOVING_STAR) {
		grid::set_fgamma(5.0 / 3.0);
		grid::set_analytic_func(moving_star_analytic);
		set_problem(moving_star);
		set_refine_test(refine_test_bibi);
		/*} else if (opts.problem == OLD_SCF) {
		 set_refine_test(refine_test_bibi);
		 set_problem(init_func_type([=](real a, real b, real c, real dx) {
		 return old_scf(a,b,c,opts.omega,opts.core_thresh_1,opts.core_thresh_2, dx);
		 }));
		 if (!opts.found_restart_file) {
		 if (opts.omega < ZERO) {
		 printf("Must specify omega for bibi polytrope\n");
		 throw;
		 }
		 if (opts.core_thresh_1 < ZERO) {
		 printf("Must specify core_thresh_1 for bibi polytrope\n");
		 throw;
		 }
		 if (opts.core_thresh_2 < ZERO) {
		 printf("Must specify core_thresh_2 for bibi polytrope\n");
		 throw;
		 }
		 }*/
	} else if (opts.problem == SOLID_SPHERE) {
		hydro_on = false;
		set_problem(init_func_type([](real x, real y, real z, real dx) {
			return solid_sphere(x,y,z,dx,0.25);
		}));
	} else {
		printf("No problem specified\n");
		throw;
	}
	node_server::set_gravity(gravity_on);
	node_server::set_hydro(hydro_on);
	compute_ilist();
}
示例#2
0
  void system::set_geometry(const bool init) 
  {
    const double dt_max = 1.0/64 ; //16; // 1.0/128;
    scheduler = Scheduler(dt_max);

    t_end   = 2.5;

    n_restart = 1;
    dt_restart = dt_max;

    dt_dump = dt_max / 16;
    dt_dump = dt_max ; //* 4;

    di_log = 100;

    global_n = local_n = 0;
    int nx = 16;
    int ny = 16;
    int nz = 16;

    //		nx = ny = nz = 32;

    //		nx = ny = nz = 64;

    nx = ny = 32; nz = 32;

    //		nx = ny = 32; nz = 16;
    nx = ny = 64; nz = 16;
     nx = ny = 128; nz = 16;
    // nx = ny = 256; nz = 16;


    //		nx = ny = 256;	nz = 256;


    //		nx = ny = nz = 128;

    //		eulerian = true;


#if 0
#if 1
#define __ADVECT_PULSE_TEST__
    nx = ny = 64;	nz = 16;
    dt_dump = dt_max;
    dt_restart = 1e10;
#endif
    //		nx = ny = 128;
#endif


    const double Lx = 1.0;
    const vec3 rmin(0.0);
    const vec3 rmax(Lx, (Lx/nx)*ny, (Lx/nx)*nz);
    global_domain = boundary(rmin, rmax);
    global_domain_size = global_domain.hsize() * 2.0;

    const vec3 Len3 = global_domain.hsize() * 2.0;
    pfloat<0>::set_scale(Len3.x);
    pfloat<1>::set_scale(Len3.y);
    pfloat<2>::set_scale(Len3.z);

    Distribute::int3 nt(1, 1, 1);
    switch(nproc) 
    {
      case 1: break;
      case 2: nt.x = 2; nt.y = 1; nt.z = 1; break;
      case 4: nt.x = 2; nt.y = 2; nt.z = 1; break;
      case 8: nt.x = 4; nt.y = 2; nt.z = 1; break;
      case 16: nt.x = 4; nt.y = 4; nt.z = 1; break;
      case 32: nt.x = 8; nt.y = 4; nt.z = 1; break;
      case 64: nt.x = 8; nt.y = 8; nt.z = 1; break;
      case 128: nt.x = 8; nt.y = 8; nt.z = 2; break;
      default: assert(false);
    }

    const Distribute::int3 nt_glb(nt);
    const pBoundary pglobal_domain(pfloat3(0.0), pfloat3(Len3));
    distribute_glb.set(nproc, nt, pglobal_domain);

    if (!init) return;

    if (myproc == 0) 
    {

      ptcl_local.clear();
      ptcl_local.reserve(128);

      const dvec3 dr = dvec3(Len3.x/nx, Len3.y/ny, Len3.z/nz);
      const real rmax = dr.abs() * 1.0;

      fprintf(stderr, "dr= %g %g %g \n", dr.x, dr.y, dr.z);
      fprintf(stderr, "rmin= %g %g %g \n", 
          global_domain.get_rmin().x,
          global_domain.get_rmin().y,
          global_domain.get_rmin().z);
      fprintf(stderr, "rmax= %g %g %g \n", 
          global_domain.get_rmax().x,
          global_domain.get_rmax().y,
          global_domain.get_rmax().z);

      for (int k = 0; k < nz; k++) {
        for (int j = 0; j < ny; j++) {
          for (int i = 0; i < nx; i++) {
            dvec3 pos = global_domain.get_rmin() + dvec3(i*dr.x, j*dr.y, k*dr.z) + 0.5*dr;
            const int ijk = (k*ny + j)*nx + i;
#if 0
            if (!eulerian)
            {
              const real f = 1.0e-6;
              pos += vec3(drand48()*dr.x*f, drand48()*dr.y*f, drand48()*dr.z*f);
            }
#endif


#if 1
            pos = global_domain.get_rmin() + dvec3(
                drand48()*Len3.x,
                drand48()*Len3.y,
                drand48()*Len3.z);
#else
#define _UNIFORM_MESH_
#endif
            dvec3 vel(0.0, 0.0, 0.0);
            Particle p;
            p.set_pos(pos);
            p.vel = vel;
            p.orig_vel = p.vel;
            p.boundary = 0;
            p.idx = ijk;
            p.rmax = rmax;
            ptcl_local.push_back(p);
          }
        }
      }
      local_n  = ptcl_local.size();
      global_n = local_n;

      fprintf(stderr, "  *** proc= %d : local_n= %llu  global_n= %llu \n", myproc, local_n, global_n);
    } // myproc == 0

    MPI_Bcast(&global_n,  1, MPI_INT, 0, MPI_COMM_WORLD);

    MPI_Barrier(MPI_COMM_WORLD);
    if (myproc == 0)
      fprintf(stderr, " ***  Distrubiting data \n");

    all_active = true;

    for (int k = 0; k < 5; k++)
      distribute_data(false,false,false);

#if 0
    std::vector< std::pair<int, TREAL> > rmax_list;
    local_tree.root.get_rmax(rmax_list);
    assert((int)rmax_list.size() == local_n);
    for (int i = 0; i < local_n; i++)
      ptcl[rmax_list[i].first].rmax = rmax_list[i].second;
#endif

    MPI_Barrier(MPI_COMM_WORLD);
    fprintf(stderr, " *** proc= %d : local_n= %llu  global_n= %llu \n", myproc, local_n, global_n);
    fprintf(stderr, " proc= %d  relax \n", myproc);

#ifndef _UNIFORM_MESH_
    relax_mesh(5);
#endif
    fprintf(stderr, " ---- done --- \n");
    {
      distribute_data(false, false, false);
      const double t10 = mytimer::get_wtime();
      clear_mesh(false);
      int nattempt = build_mesh_global();
      double dt10 = mytimer::get_wtime() - t10;

      double volume_loc = 0.0;
      {
        std::vector<TREAL> v(local_n);
        for (int i = 0; i < (int)local_n; i++)
          v[i] = cell_local[i].Volume;
        std::sort(v.begin(), v.end());  // sort volumes from low to high, to avoid roundoff errors
        for (int i = 0; i < (int)local_n; i++)
          volume_loc += v[i];
      }


      double dt10max;
      MPI_Allreduce(&dt10, &dt10max, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
      double volume_glob = 0.0;	
      int    nattempt_max, nattempt_min;
      MPI_Allreduce(&volume_loc, &volume_glob,  1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(&nattempt,   &nattempt_max, 1, MPI_INT,    MPI_MAX, MPI_COMM_WORLD);
      MPI_Allreduce(&nattempt,   &nattempt_min, 1, MPI_INT,    MPI_MIN, MPI_COMM_WORLD);

      const double volume_exact = global_domain_size.x*global_domain_size.y*global_domain_size.z;
      if (myproc == 0)
      {
        fprintf(stderr, "first call build_mesh:[ %g  sec ::  %g cells/s/proc/thread ]\n",
            dt10max,
            global_n/nproc/dt10max);
        fprintf(stderr, "   computed_volume= %g  exact_volume= %g diff= %g [ %g ]  nattempt= %d %d \n",
            volume_glob, volume_exact, 
            volume_glob - volume_exact,	(volume_glob - volume_exact)/volume_exact,
            nattempt_min, nattempt_max);
      }
    }


    extract_ngb_from_mesh();
#if 0
    set_problem(true);
    iterate();

    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
    exit(-1);
#endif
  }
示例#3
0
int hpx_main(int argc, char* argv[]) {
	printf("Running\n");
// 	auto test_fut = hpx::async([]() {
//		while(1){hpx::this_thread::yield();}
// 	});
// 	test_fut.get();

	try {
		if (opts.process_options(argc, argv)) {

			auto all_locs = hpx::find_all_localities();
			std::vector<hpx::future<void>> futs;
            futs.reserve(all_locs.size());
			for (auto i = all_locs.begin(); i != all_locs.end(); ++i) {
				futs.push_back(hpx::async < initialize_action > (*i, opts));
			}
            hpx::when_all(futs).get();

			node_client root_id = hpx::new_ < node_server > (hpx::find_here());
			node_client root_client(root_id);

			if (opts.found_restart_file) {
				set_problem(null_problem);
				const std::string fname = opts.restart_filename;
				printf("Loading from %s...\n", fname.c_str());
				if (opts.output_only) {
					const std::string oname = opts.output_filename;
					root_client.get_ptr().get()->load_from_file_and_output(fname, oname);
				} else {
					root_client.get_ptr().get()->load_from_file(fname);
					root_client.regrid(root_client.get_gid(), true).get();
				}
				printf("Done. \n");
			} else {
				for (integer l = 0; l < opts.max_level; ++l) {
					root_client.regrid(root_client.get_gid(), false).get();
					printf("---------------Created Level %i---------------\n\n", int(l + 1));
				}
				root_client.regrid(root_client.get_gid(), false).get();
				printf("---------------Regridded Level %i---------------\n\n", int(opts.max_level));
			}

			std::vector < hpx::id_type > null_sibs(geo::direction::count());
			printf("Forming tree connections------------\n");
			root_client.form_tree(root_client.get_gid(), hpx::invalid_id, null_sibs).get();
			if (gravity_on) {
				//real tstart = MPI_Wtime();
				root_client.solve_gravity(false).get();
				//	printf("Gravity Solve Time = %e\n", MPI_Wtime() - tstart);
			}
			printf("...done\n");

			if (!opts.output_only) {
				//	set_problem(null_problem);
				root_client.start_run(opts.problem == DWD && !opts.found_restart_file).get();
			}
            root_client.report_timing();
		}
	} catch (...) {
        throw;
	}
	printf("Exiting...\n");
	return hpx::finalize();
}
示例#4
0
int
main (int argc, char **argv)
{
  char *filename;
  int opt, instances, counter;
  FILE *instance_file;
  knapsack_t *problem;
  evolve_int_pop_t *population;
  evolve_stats_t *stats;
  evolve_settings_t *settings;
  evolve_object_t *solution;

  size_t generations = MAX_GEN;
  size_t xover_points = 5;
  size_t tournament_size = (size_t) POP_SIZE / 2;
  size_t selection_size = POP_SIZE;
  size_t ivf_num_parents = (size_t) POP_SIZE / 2;
  double xover_rate = 0.7;
  double recombination_parameterized = 0.8;
  double mutation_rate = 0.8;

  if (argc < 2)
    {
      fprintf (stderr, USAGE);
      return 0;
    }
  while ((opt = getopt (argc, argv, "h")) != -1)
    {
      switch (opt)
        {
          case 'h':
            fprintf (stdout, USAGE);
            return 0;
          case '?':
            if (isprint (optopt))
              fprintf (stderr, "Unknown option '-%c'.\n", optopt);
            else
              fprintf (stderr, "Unknown option character '\\x%x'.\n", optopt);
            fprintf (stderr, USAGE);
            return 1;
          default:
            abort ();
        }
    }
  if (optind == argc)
    {
      fprintf (stderr, "Error: missing [file-name] element\n");
      fprintf (stderr, USAGE);
      return 1;
    }
  filename = argv[optind];
  instance_file = fopen (filename, "r");
  fscanf (instance_file, "%d\n", &instances);

  for(counter = 0; counter < instances; counter++)
    {
      problem = init_instance (instance_file);
      if (problem == NULL)
        return 0;

      set_problem (problem);
      evolve_set_rng (SEED);
      population = evolve_init_int_pop (POP_SIZE);
      evolve_random_int_pop (population, problem->items, &check);

      settings = evolve_settings_init ();
      settings->set_own_property (settings, "population", population);
      settings->set_own_property (settings, "generations", &generations);
      settings->set_own_property (settings, "fitness", &fitness);
      settings->set_own_property (settings, "breed", &evolve_ga_breed);
      settings->set_chain (settings, "strategies.check_chrom", &check);
      settings->set_chain (settings, "strategies.recombination_strategy", &evolve_ga_npoint_xover);
      settings->set_chain (settings, "strategies.recombination.num_points", &xover_points);
      settings->set_chain (settings, "strategies.recombination.xover_rate", &xover_rate);
      settings->set_chain (settings, "strategies.recombination.parameterized", &recombination_parameterized);
      settings->set_chain (settings, "strategies.mutation_strategy", &evolve_ga_per_int_mutation);
      settings->set_chain (settings, "strategies.mutation.chance", &mutation_rate);
      settings->set_chain (settings, "strategies.selection_strategy", &evolve_ga_roulette_wheel_selection);
      settings->set_chain (settings, "strategies.selection.tournament_size", &tournament_size);
      settings->set_chain (settings, "strategies.selection.total_size", &selection_size);
      settings->set_chain (settings, "strategies.replacement_policy", &evolve_ga_elitist_policy_replacement);
      settings->set_chain (settings, "strategies.ivf.recombination_strategy", &evolve_ga_npoint_xover);
      settings->set_chain (settings, "strategies.ivf.recombination.num_points", &xover_points);
      settings->set_chain (settings, "strategies.ivf.num_parents", &ivf_num_parents);

      solution = evolve_ivfga_init ();
      stats = (evolve_stats_t *) solution->execute_property (solution, "solution", settings);

      printf ("\n");
      evolve_print_algo_info ("GA:", "Multidimensional 0-1 Knapsack Problem", MAX_GEN, POP_SIZE, SEED);
      evolve_print_int_pop (population, stats);
      printf ("\n");

      evolve_tear_rng ();
      evolve_del_settings (settings);
      evolve_del_object (solution);
      evolve_del_stats (stats);
      evolve_del_int_pop_indiv (population);
      evolve_del_int_pop (population);

      del_knapsack (problem);
    }

  fclose (instance_file);

  return 0;
}