tstParallelDepletion.cpp

./Manager/mzd/tests/tstParallelDepletion.cpp

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include "ScaleUtils/IO/DB.h"
#include "Nemesis/gtest/nemesis_gtest.hh"
#include "Origen/Core/TestPaths.h"
#include "Origen/Core/config.h"
#include "Standard/Interface/AbstractWriter.h"
#include "Standard/Interface/BasicIOWriter.h"
#include "Standard/Interface/Communicator.h"
using ScaleUtils::IO::nprintf;
// GLOBAL COMMUNICATOR
Standard::Communicator world;
TEST( Parallel, Basic )
{
std::cout << "hi i am " << world.host() << "." << world.rank() << std::endl;
// warm up
world.barrier();
{
double x = 1;
for( size_t j = 0; j < 5e7; ++j )
{
x = x * 2 / 6.;
}
(void)x;
}
// for real
world.barrier();
{
SCOPED_TIMER( "total time" );
double x = 1;
for( size_t j = 0; j < 1e9; ++j )
{
x = x * 2 / 6.;
}
(void)x;
}
world.barrier();
if( world.rank() == 0 ) Origen::printTimingReport( std::cout );
}
TEST( Parallel, WeakScaling )
{
// Get a transition matrix and library.
{
SCOPED_TIMER( "load time" );
//**********************************************************************
//**********************************************************************
// This test is only active if DATA is defined.
//**********************************************************************
//**********************************************************************
std::string DATA = ScaleUtils::IO::getEnv( "DATA" );
if( DATA == "" ) return;
//**********************************************************************
//**********************************************************************
ScaleUtils::IO::DB opts;
Origen::loadLibrary( Origen::pwrlib_filepath, opts ) );
opts.throwErrorStack();
trx = lib->newsp_transition_matrix_at( 0 );
}
world.barrier();
// open a file for each process
std::ofstream ofs(
nprintf( "%s.%05d.log", world.host().c_str(), world.rank() ) );
// divide materials evenly into number of processes, taking extra
// into head node
int num_mat_total = 1 * world.size();
{
SCOPED_TIMER( "mat time" );
std::vector<int> ids;
std::vector<double> numden;
int num_mat = num_mat_total / world.size();
if( world.rank() == 0 ) num_mat += num_mat_total % num_mat;
// ofs << "num_mat=" << num_mat <<std::endl;
std::vector<int> mat_count;
world.allgather( num_mat, mat_count );
int id = 0;
for( size_t r = 0; r < mat_count.size(); ++r )
{
if( r == world.rank() )
{
// output ofs << "materials=[ ";
for( size_t m = 0; m < mat_count[r]; ++m )
{
++id;
std::string name = nprintf( "mat%d", id );
double volume = 5.6;
"GENERAL", lib, name, id, volume ) );
mat->set_numden_bos( numden, ids );
matmap->add( mat );
// output ofs << name << " ";
}
// output ofs <<"]"<<std::endl;
}
id += mat_count[r];
}
}
world.barrier();
// Create depletion times/fluxes.
// cycle1-------------->
// deplete------>decay->
std::vector<double> time{0, 3, 250, 500, 515, 530};
std::vector<double> flux{1, 1, 1, 0, 0};
for( size_t j = 0; j < time.size(); ++j ) time[j] *= 86400.0;
for( size_t j = 0; j < flux.size(); ++j ) flux[j] *= 1e14;
size_t nsteps = flux.size();
// Create step depleter.
DataContainer dc;
// set solver
mzd.set_solver( slv );
// set materials
mzd.set_materials( matmap );
// set communicator
mzd.set_comm( &world );
dc.addInt( "numSubsteps", 1 );
dc.addBool( "depleteByPower", false );
dc.addDouble(
"systemPower",
8e2 * num_mat_total ); // Watts (needs to scale up with materials)
// Enter step loop.
world.barrier();
{
SCOPED_TIMER( "full" );
for( size_t j = 0; j < nsteps; ++j )
{
SCOPED_TIMER( nprintf( "loop(%03d)", ( j + 1 ) ) );
// Add new step data.
double stepTime = time[j + 1] - time[j];
for( auto it = matmap->begin(); it != matmap->end(); ++it )
{
it->second->add_step( stepTime );
it->second->set_flux( flux[j] );
it->second->set_transition_matrix( trx );
}
// Update data container.
dc.addDouble( "stepTime", stepTime );
mzd.update( dc );
// Step in time.
mzd.execute();
// Output
/*
for(auto it=matmap->begin(); it!=matmap->end(); ++it){
double dt = it->second->dt();
double flux = it->second->flux();
double power = it->second->power();
std::string outline =
nprintf("matid=%10d step=%3d dt=%12.3e flux=%12.3e
power=%12.3e\n",
it->first,(j+1),dt,flux,power);
ofs << outline;
}
*/
}
}
world.barrier();
if( world.rank() == 0 ) Origen::printTimingReport( std::cout );
}
TEST( Parallel, DISABLED_StrongScaling )
{
// Get a transition matrix and library.
{
SCOPED_TIMER( "load time" );
//**********************************************************************
//**********************************************************************
// This test is only active if DATA is defined.
//**********************************************************************
//**********************************************************************
std::string DATA = ScaleUtils::IO::getEnv( "DATA" );
if( DATA == "" ) return;
//**********************************************************************
//**********************************************************************
ScaleUtils::IO::DB opts;
Origen::loadLibrary( Origen::pwrlib_filepath, opts ) );
opts.throwErrorStack();
trx = lib->newsp_transition_matrix_at( 0 );
}
world.barrier();
// open a file for each process
std::ofstream ofs(
nprintf( "%s.%05d.log", world.host().c_str(), world.rank() ) );
// divide materials evenly into number of processes, taking extra
// into head node
int num_mat_total = 4; // 6144;
{
SCOPED_TIMER( "mat time" );
std::vector<int> ids;
std::vector<double> numden;
int num_mat = num_mat_total / world.size();
if( world.rank() == 0 ) num_mat += num_mat_total % num_mat;
// output ofs << "num_mat=" << num_mat <<std::endl;
std::vector<int> mat_count;
world.allgather( num_mat, mat_count );
int id = 0;
for( size_t r = 0; r < mat_count.size(); ++r )
{
if( r == world.rank() )
{
// output ofs << "materials=[ ";
for( size_t m = 0; m < mat_count[r]; ++m )
{
++id;
std::string name = nprintf( "mat%d", id );
double volume = 5.6;
"GENERAL", lib, name, id, volume ) );
mat->set_numden_bos( numden, ids );
matmap->add( mat );
// output ofs << name << " ";
}
// output ofs <<"]"<<std::endl;
}
id += mat_count[r];
}
}
world.barrier();
// Create depletion times/fluxes.
// cycle1-------------->
// deplete------>decay->
std::vector<double> time{0, 3, 250, 500, 515, 530};
std::vector<double> flux{1, 1, 1, 0, 0};
for( size_t j = 0; j < time.size(); ++j ) time[j] *= 86400.0;
size_t nsteps = flux.size();
// Create step depleter.
// set solver
mzd.set_solver( slv );
// set materials
mzd.set_materials( matmap );
// set communicator
mzd.set_comm( &world );
mzd.set_power_constraint( 4.9e6 );
mzd.set_substep_dtrel( {1.0} );
// Enter step loop.
world.barrier();
{
SCOPED_TIMER( "full" );
for( size_t j = 0; j < nsteps; ++j )
{
SCOPED_TIMER( nprintf( "loop(%03d)", ( j + 1 ) ) );
// Add new step data.
mzd.add_step( time[j + 1] - time[j] );
for( auto it = matmap->begin(); it != matmap->end(); ++it )
{
it->second->set_flux( flux[j] );
it->second->set_transition_matrix( trx );
}
// Step in time.
mzd.execute();
// Output
/*
for(auto it=matmap->begin(); it!=matmap->end(); ++it){
double dt = it->second->dt();
double flux = it->second->flux();
double power = it->second->power();
std::string outline =
nprintf("matid=%10d step=%3d dt=%12.3e flux=%12.3e
power=%12.3e\n",
it->first,(j+1),dt,flux,power);
ofs << outline;
}
ofs << mzd.status();
*/
}
}
world.barrier();
if( world.rank() == 0 ) Origen::printTimingReport( std::cout );
}