int main(int argc, char* argv[]) { BoxLib::Initialize(argc,argv); BL_PROFILE_VAR("main()", pmain); const Real strt_total = ParallelDescriptor::second(); { AmrAdv amradv; amradv.InitData(); amradv.Evolve(); Real end_total = ParallelDescriptor::second() - strt_total; ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber()); if (amradv.Verbose() && ParallelDescriptor::IOProcessor()) { std::cout << "\nTotal Time : " << end_total << '\n'; } } BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); }
int main(int argc, char* argv[]) { BoxLib::Initialize(argc,argv); BL_PROFILE_VAR("main()", pmain); std::cout << std::setprecision(15); solver_type = BoxLib_C; bc_type = Periodic; Real a = 0.0; Real b = 1.0; // ---- First use the number of processors to decide how many grids you have. // ---- We arbitrarily decide to have one grid per MPI process in a uniform // ---- cubic domain, so we require that the number of processors be N^3. // ---- This requirement is somewhat arbitrary, but convenient for now. int nprocs = ParallelDescriptor::NProcs(); // N is the cube root of the number of processors int N(0); for(int i(1); i*i*i <= nprocs; ++i) { if(i*i*i == nprocs) { N = i; } } if(N == 0) { // not a cube if(ParallelDescriptor::IOProcessor()) { std::cerr << "**** Error: nprocs = " << nprocs << " is not currently supported." << std::endl; } BoxLib::Error("We require that the number of processors be a perfect cube"); } if(ParallelDescriptor::IOProcessor()) { std::cout << "N = " << N << std::endl; } // ---- make a box, then a boxarray with maxSize int domain_hi = (N*maxGrid) - 1; Box domain(IntVect(0,0,0), IntVect(domain_hi,domain_hi,domain_hi)); BoxArray bs(domain); bs.maxSize(maxGrid); // This defines the physical size of the box. Right now the box is [0,1] in each direction. RealBox real_box; for (int n = 0; n < BL_SPACEDIM; n++) { real_box.setLo(n, 0.0); real_box.setHi(n, 1.0); } // This says we are using Cartesian coordinates int coord = 0; // This sets the boundary conditions to be periodic or not int is_per[BL_SPACEDIM]; if (bc_type == Dirichlet || bc_type == Neumann) { for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 0; } else { for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 1; } // This defines a Geometry object which is useful for writing the plotfiles Geometry geom(domain,&real_box,coord,is_per); for ( int n=0; n<BL_SPACEDIM; n++ ) { dx[n] = ( geom.ProbHi(n) - geom.ProbLo(n) )/domain.length(n); } if (ParallelDescriptor::IOProcessor()) { std::cout << "Domain size : " << N << std::endl; std::cout << "Max_grid_size : " << maxGrid << std::endl; std::cout << "Number of grids : " << bs.size() << std::endl; } // Allocate and define the right hand side. MultiFab rhs(bs, Ncomp, 0, Fab_allocate); setup_rhs(rhs, geom, a, b); MultiFab alpha(bs, Ncomp, 0, Fab_allocate); MultiFab beta[BL_SPACEDIM]; for ( int n=0; n<BL_SPACEDIM; ++n ) { BoxArray bx(bs); beta[n].define(bx.surroundingNodes(n), Ncomp, 1, Fab_allocate); } setup_coeffs(bs, alpha, beta, geom); MultiFab anaSoln; if (comp_norm) { anaSoln.define(bs, Ncomp, 0, Fab_allocate); compute_analyticSolution(anaSoln); } // Allocate the solution array // Set the number of ghost cells in the solution array. MultiFab soln(bs, Ncomp, 1, Fab_allocate); solve(soln, anaSoln, a, b, alpha, beta, rhs, bs, geom, BoxLib_C); BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); }
int main(int argc, char* argv[]) { BoxLib::Initialize(argc,argv); BL_PROFILE_VAR("main()", pmain); std::cout << std::setprecision(15); ParmParse ppmg("mg"); ppmg.query("v", verbose); ppmg.query("maxorder", maxorder); ParmParse pp; { std::string solver_type_s; pp.get("solver_type",solver_type_s); if (solver_type_s == "BoxLib_C") { solver_type = BoxLib_C; } else if (solver_type_s == "BoxLib_C4") { solver_type = BoxLib_C4; } else if (solver_type_s == "BoxLib_F") { #ifdef USE_F90_SOLVERS solver_type = BoxLib_F; #else BoxLib::Error("Set USE_FORTRAN=TRUE in GNUmakefile"); #endif } else if (solver_type_s == "Hypre") { #ifdef USEHYPRE solver_type = Hypre; #else BoxLib::Error("Set USE_HYPRE=TRUE in GNUmakefile"); #endif } else if (solver_type_s == "All") { solver_type = All; } else { if (ParallelDescriptor::IOProcessor()) { std::cout << "Don't know this solver type: " << solver_type << std::endl; } BoxLib::Error(""); } } { std::string bc_type_s; pp.get("bc_type",bc_type_s); if (bc_type_s == "Dirichlet") { bc_type = Dirichlet; #ifdef USEHPGMG domain_boundary_condition = BC_DIRICHLET; #endif } else if (bc_type_s == "Neumann") { bc_type = Neumann; #ifdef USEHPGMG BoxLib::Error("HPGMG does not support Neumann boundary conditions"); #endif } else if (bc_type_s == "Periodic") { bc_type = Periodic; #ifdef USEHPGMG domain_boundary_condition = BC_PERIODIC; #endif } else { if (ParallelDescriptor::IOProcessor()) { std::cout << "Don't know this boundary type: " << bc_type << std::endl; } BoxLib::Error(""); } } pp.query("tol_rel", tolerance_rel); pp.query("tol_abs", tolerance_abs); pp.query("maxiter", maxiter); pp.query("plot_rhs" , plot_rhs); pp.query("plot_beta", plot_beta); pp.query("plot_soln", plot_soln); pp.query("plot_asol", plot_asol); pp.query("plot_err", plot_err); pp.query("comp_norm", comp_norm); Real a, b; pp.get("a", a); pp.get("b", b); pp.get("n_cell",n_cell); pp.get("max_grid_size",max_grid_size); // Define a single box covering the domain IntVect dom_lo(D_DECL(0,0,0)); IntVect dom_hi(D_DECL(n_cell-1,n_cell-1,n_cell-1)); Box domain(dom_lo,dom_hi); // Initialize the boxarray "bs" from the single box "bx" BoxArray bs(domain); // Break up boxarray "bs" into chunks no larger than "max_grid_size" along a direction bs.maxSize(max_grid_size); // This defines the physical size of the box. Right now the box is [0,1] in each direction. RealBox real_box; for (int n = 0; n < BL_SPACEDIM; n++) { real_box.setLo(n, 0.0); real_box.setHi(n, 1.0); } // This says we are using Cartesian coordinates int coord = 0; // This sets the boundary conditions to be periodic or not Array<int> is_per(BL_SPACEDIM,1); if (bc_type == Dirichlet || bc_type == Neumann) { if (ParallelDescriptor::IOProcessor()) { std::cout << "Using Dirichlet or Neumann boundary conditions." << std::endl; } for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 0; } else { if (ParallelDescriptor::IOProcessor()) { std::cout << "Using periodic boundary conditions." << std::endl; } for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 1; } // This defines a Geometry object which is useful for writing the plotfiles Geometry geom(domain,&real_box,coord,is_per.dataPtr()); for ( int n=0; n<BL_SPACEDIM; n++ ) { dx[n] = ( geom.ProbHi(n) - geom.ProbLo(n) )/domain.length(n); } if (ParallelDescriptor::IOProcessor()) { std::cout << "Grid resolution : " << n_cell << " (cells)" << std::endl; std::cout << "Domain size : " << real_box.hi(0) - real_box.lo(0) << " (length unit) " << std::endl; std::cout << "Max_grid_size : " << max_grid_size << " (cells)" << std::endl; std::cout << "Number of grids : " << bs.size() << std::endl; } // Allocate and define the right hand side. bool do_4th = (solver_type==BoxLib_C4 || solver_type==All); int ngr = (do_4th ? 1 : 0); MultiFab rhs(bs, Ncomp, ngr); setup_rhs(rhs, geom); // Set up the Helmholtz operator coefficients. MultiFab alpha(bs, Ncomp, 0); PArray<MultiFab> beta(BL_SPACEDIM, PArrayManage); for ( int n=0; n<BL_SPACEDIM; ++n ) { BoxArray bx(bs); beta.set(n, new MultiFab(bx.surroundingNodes(n), Ncomp, 0, Fab_allocate)); } // The way HPGMG stores face-centered data is completely different than the // way BoxLib does it, and translating between the two directly via indexing // magic is a nightmare. Happily, the way this tutorial calculates // face-centered values is by first calculating cell-centered values and then // interpolating to the cell faces. HPGMG can do the same thing, so rather // than converting directly from BoxLib's face-centered data to HPGMG's, just // give HPGMG the cell-centered data and let it interpolate itself. MultiFab beta_cc(bs,Ncomp,1); // cell-centered beta setup_coeffs(bs, alpha, beta, geom, beta_cc); MultiFab alpha4, beta4; if (do_4th) { alpha4.define(bs, Ncomp, 4, Fab_allocate); beta4.define(bs, Ncomp, 3, Fab_allocate); setup_coeffs4(bs, alpha4, beta4, geom); } MultiFab anaSoln; if (comp_norm || plot_err || plot_asol) { anaSoln.define(bs, Ncomp, 0, Fab_allocate); compute_analyticSolution(anaSoln,Array<Real>(BL_SPACEDIM,0.5)); if (plot_asol) { writePlotFile("ASOL", anaSoln, geom); } } // Allocate the solution array // Set the number of ghost cells in the solution array. MultiFab soln(bs, Ncomp, 1); MultiFab soln4; if (do_4th) { soln4.define(bs, Ncomp, 3, Fab_allocate); } MultiFab gphi(bs, BL_SPACEDIM, 0); #ifdef USEHYPRE if (solver_type == Hypre || solver_type == All) { if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; std::cout << "Solving with Hypre " << std::endl; } solve(soln, anaSoln, gphi, a, b, alpha, beta, beta_cc, rhs, bs, geom, Hypre); } #endif if (solver_type == BoxLib_C || solver_type == All) { if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; std::cout << "Solving with BoxLib C++ solver " << std::endl; } solve(soln, anaSoln, gphi, a, b, alpha, beta, beta_cc, rhs, bs, geom, BoxLib_C); } if (solver_type == BoxLib_C4 || solver_type == All) { if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; std::cout << "Solving with BoxLib C++ 4th order solver " << std::endl; } solve4(soln4, anaSoln, a, b, alpha4, beta4, rhs, bs, geom); } #ifdef USE_F90_SOLVERS if (solver_type == BoxLib_F || solver_type == All) { if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; std::cout << "Solving with BoxLib F90 solver " << std::endl; } solve(soln, anaSoln, gphi, a, b, alpha, beta, beta_cc, rhs, bs, geom, BoxLib_F); } #endif #ifdef USEHPGMG if (solver_type == HPGMG || solver_type == All) { if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; std::cout << "Solving with HPGMG solver " << std::endl; } solve(soln, anaSoln, gphi, a, b, alpha, beta, beta_cc, rhs, bs, geom, HPGMG); } #endif if (ParallelDescriptor::IOProcessor()) { std::cout << "----------------------------------------" << std::endl; } BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); }
int main (int argc, char** argv) { BoxLib::Initialize(argc, argv); BL_PROFILE_VAR("main()", pmain); Array<DistributionMapping::Strategy> dmStrategies(nStrategies); dmStrategies[0] = DistributionMapping::ROUNDROBIN; dmStrategies[1] = DistributionMapping::KNAPSACK; dmStrategies[2] = DistributionMapping::SFC; dmStrategies[3] = DistributionMapping::PFC; Array<std::string> dmSNames(nStrategies); dmSNames[0] = "ROUNDROBIN"; dmSNames[1] = "KNAPSACK"; dmSNames[2] = "SFC"; dmSNames[3] = "PFC"; Array<double> dmSTimes(nStrategies, 0.0); for(int iS(0); iS < nStrategies * nTimes; ++iS) { int whichStrategy(iS % nStrategies); DistributionMapping::strategy(dmStrategies[whichStrategy]); // Box bx(IntVect(0,0,0),IntVect(511,511,255)); // Box bx(IntVect(0,0,0),IntVect(1023,1023,255)); Box bx(IntVect(0,0,0),IntVect(1023,1023,1023)); // Box bx(IntVect(0,0,0),IntVect(2047,2047,1023)); // Box bx(IntVect(0,0,0),IntVect(127,127,127)); // Box bx(IntVect(0,0,0),IntVect(255,255,255)); BoxArray ba(bx); ba.maxSize(64); const int N = 2000; // This should be divisible by 4 !!! if (ParallelDescriptor::IOProcessor() && iS == 0) { std::cout << "Domain: " << bx << " # boxes in BoxArray: " << ba.size() << '\n'; } if (ParallelDescriptor::IOProcessor()) std::cout << "Strategy: " << dmSNames[DistributionMapping::strategy()] << '\n'; ParallelDescriptor::Barrier(); { // // A test of FillBoundary() on 1 grow cell with cross stencil. // MultiFab mf(ba,1,1); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N; i++) mf.FillBoundary(true); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << N << " cross x 1: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // A test of FillBoundary() on 1 grow cell with dense stencil. // MultiFab mf(ba,1,1); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << N << " dense x 1: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // First a test of FillBoundary() on 2 grow cells with dense stencil. // MultiFab mf(ba,1,2); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N/2; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << (N/2) << " dense x 2: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // First a test of FillBoundary() on 4 grow cells with dense stencil. // MultiFab mf(ba,1,4); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N/4; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << (N/4) << " dense x 4: " << end << std::endl; dmSTimes[whichStrategy] += end; } } if (ParallelDescriptor::IOProcessor()) std::cout << std::endl; } // end for iS if(ParallelDescriptor::IOProcessor()) { for(int i(0); i < nStrategies; ++i) { std::cout << std::endl << "Total times:" << std::endl; std::cout << dmSNames[i] << " time = " << dmSTimes[i] << std::endl; } std::cout << std::endl << std::endl; } BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); return 0; }