MADNESS  version 0.9
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
madness::World Class Reference

A parallel world with full functionality wrapping an MPI communicator. More...

#include <worldfwd.h>

Inheritance diagram for madness::World:
Inheritance graph
[legend]
Collaboration diagram for madness::World:
Collaboration graph
[legend]

Public Member Functions

 World (const SafeMPI::Intracomm &comm)
 
void set_user_state (void *state)
 Sets a pointer to user-managed local state. More...
 
void * get_user_state ()
 Returns pointer to user-managed state set by set_user_state() More...
 
void clear_user_state ()
 Clears user-defined state ... same as set_user_state(0) More...
 
void args (int argc, char **argv)
 Processes command line arguments. More...
 
unsigned long id () const
 Returns the system-wide unique integer ID of this world. More...
 
ProcessID rank () const
 Returns the process rank in this world (same as MPI_Comm_rank())) More...
 
ProcessID nproc () const
 Returns the number of processes in this world (same as MPI_Comm_size()) More...
 
ProcessID size () const
 Returns the number of processes in this world (same as MPI_Comm_size()) More...
 
uniqueidT unique_obj_id ()
 Returns new universe-wide unique ID for objects created in this world. No comms. More...
 
template<typename T >
uniqueidT register_ptr (T *ptr)
 Associate a local pointer with a universe-wide unique id. More...
 
template<typename T >
void unregister_ptr (T *ptr)
 Unregister a unique id for a local pointer. More...
 
template<typename T >
void unregister_ptr (const uniqueidT id)
 Unregister a unique id for a local pointer based on id. More...
 
template<typename T >
T * ptr_from_id (uniqueidT id) const
 Look up local pointer from world-wide unique id. More...
 
template<typename T >
const uniqueidTid_from_ptr (T *ptr) const
 Look up id from local pointer. More...
 
void srand (unsigned long seed=0ul)
 
int rand ()
 Returns a CRUDE, LOW-QUALITY, random number uniformly distributed in [0,2**24). More...
 
double drand ()
 Returns a CRUDE, LOW-QUALITY, random number uniformly distributed in [0,1). More...
 
ProcessID random_proc ()
 Returns a random process number [0,world.size()) More...
 
ProcessID random_proc_not_me ()
 Returns a random process number [0,world.size()) != current process. More...
 
 ~World ()
 

Static Public Member Functions

static Worldfind_instance (const SafeMPI::Intracomm &comm)
 Find the World corresponding to the given communicator. More...
 
static Worldget_default ()
 Default World object accessor. More...
 
static Worldworld_from_id (unsigned long id)
 Convert world id to world pointer. More...
 
static void await (SafeMPI::Request &request, bool dowork=true)
 Wait for MPI request to complete. More...
 
template<typename Probe >
static void await (const Probe &probe, bool dowork=true)
 Gracefully wait for a condition to become true ... executes tasks if any in queue. More...
 

Public Attributes

WorldMpiInterfacempi
 MPI interface. More...
 
WorldAmInterfaceam
 AM interface. More...
 
WorldTaskQueuetaskq
 Task queue. More...
 
WorldGopInterfacegop
 Global operations. More...
 

Friends

class WorldAmInterface
 
class WorldGopInterface
 
Worldinitialize (int &, char **&, const SafeMPI::Intracomm &)
 Initialize the MADNESS runtime. More...
 
void finalize ()
 Call this once at the very end of your main program instead of calling MPI_Finalize. More...
 

Detailed Description

A parallel world with full functionality wrapping an MPI communicator.

Multiple worlds with different communicators can co-exist.

Constructor & Destructor Documentation

madness::World::World ( const SafeMPI::Intracomm comm)

Give me a communicator and I will give you the world. Does not check if another world using the same comm already exists (use instance() to check that)

References am, madness::WorldGopInterface::barrier(), madness::WorldGopInterface::broadcast(), madness::cpu_frequency(), gop, rank(), and srand().

madness::World::~World ( )

References am, gop, mpi, and taskq.

Member Function Documentation

void madness::World::args ( int  argc,
char **  argv 
)

Processes command line arguments.

Mostly for world test codes but most usefully provides -dx option to start x debugger.

References madness::arg(), and madness::xterm_debug().

static void madness::World::await ( SafeMPI::Request request,
bool  dowork = true 
)
inlinestatic
template<typename Probe >
static void madness::World::await ( const Probe &  probe,
bool  dowork = true 
)
inlinestatic

Gracefully wait for a condition to become true ... executes tasks if any in queue.

Probe should be an object that when called returns the status.

References madness::ThreadPool::await().

void madness::World::clear_user_state ( )
inline

Clears user-defined state ... same as set_user_state(0)

double madness::World::drand ( )
inline

Returns a CRUDE, LOW-QUALITY, random number uniformly distributed in [0,1).

References rand().

static World* madness::World::find_instance ( const SafeMPI::Intracomm comm)
inlinestatic

Find the World corresponding to the given communicator.

Parameters
commthe communicator
Returns
nonzero pointer to the World that was constructed from comm ; if it does not exist, return 0.
static World& madness::World::get_default ( )
inlinestatic

Default World object accessor.

This function returns a reference to the default world object; this is the same World object that was returned by madness::initialize().

Returns
A reference to the default world.
void* madness::World::get_user_state ( )
inline

Returns pointer to user-managed state set by set_user_state()

Will be NULL if set_user_state() has not been invoked.

unsigned long madness::World::id ( ) const
inline
template<typename T >
const uniqueidT& madness::World::id_from_ptr ( T *  ptr) const
inline

Look up id from local pointer.

Returns invalid id if the ptr was not found

Referenced by unregister_ptr().

ProcessID madness::World::nproc ( ) const
inline

Returns the number of processes in this world (same as MPI_Comm_size())

References madness::WorldMpiInterface::nproc().

template<typename T >
T* madness::World::ptr_from_id ( uniqueidT  id) const
inline
int madness::World::rand ( )
inline

Returns a CRUDE, LOW-QUALITY, random number uniformly distributed in [0,2**24).

Each process has a distinct seed for the generator.

Referenced by drand(), random_proc(), random_proc_not_me(), and srand().

ProcessID madness::World::random_proc ( )
inline

Returns a random process number [0,world.size())

References rand(), and size().

Referenced by madness::FunctionImpl< Q, NDIM >::apply(), and madness::FunctionImpl< Q, NDIM >::apply_source_driven().

ProcessID madness::World::random_proc_not_me ( )
inline

Returns a random process number [0,world.size()) != current process.

Makes no sense to call this with just one process, but just in case you do it returns -1 in the hope that you won't actually use the result.

References rand(), rank(), and size().

ProcessID madness::World::rank ( ) const
inline

Returns the process rank in this world (same as MPI_Comm_rank()))

References madness::WorldMpiInterface::rank().

Referenced by madness::SCF::analyze_vectors(), madness::FunctionImpl< Q, NDIM >::apply_1d_realspace_push(), madness::GTHPseudopotential< double >::apply_potential(), madness::SCF::apply_potential(), madness::Solver< T, NDIM >::apply_potential(), madness::GTHPseudopotential< double >::apply_potential_simple(), madness::MP2::asymmetry(), madness::FunctionImpl< Q, NDIM >::binaryXX(), madness::Solver< T, NDIM >::build_fock_matrix(), madness::CIS::CIS(), compareGroundState(), compute_energy(), compute_energy_with_U(), compute_madelung_energy(), compute_madelung_energy_PWSCF(), madness::SCF::compute_residual(), madness::Solver< T, NDIM >::compute_rho(), madness::Solver< T, NDIM >::compute_rho_slow(), converge(), converge2s(), madness::create_nuclear_correlation_factor(), CubicInterpolationTable< complexd >::CubicInterpolationTable(), madness::DFT< T, NDIM >::DFT(), madness::SCF::dipole(), madness::FunctionImpl< Q, NDIM >::do_apply(), madness::FunctionImpl< Q, NDIM >::do_apply_kernel(), madness::FunctionImpl< Q, NDIM >::do_apply_kernel2(), madness::FunctionImpl< Q, NDIM >::do_apply_kernel3(), madness::Solver< T, NDIM >::do_rhs(), madness::Solver< T, NDIM >::do_rhs_simple(), madness::SCF::do_step_restriction(), doit(), doplot(), draw_plane(), madness::END_TIMER(), END_TIMER(), madness::Solver< T, NDIM >::END_TIMER(), energy(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::exists(), madness::DerivativeBase< T, NDIM >::forward_do_diff1(), madness::FunctionImpl< Q, NDIM >::forward_traverse(), madness::FunctionImpl< Q, NDIM >::gaxpy_ext(), madness::FunctionImpl< Q, NDIM >::gaxpy_inplace_reconstructed(), generate_G_vectors(), generate_R_vectors(), madness::GMRES(), madness::SCF::group_orbital_sets(), madness::FunctionImpl< Q, NDIM >::hartree_product(), madness::MP2::increment(), madness::TDA_TIMER::info(), madness::Solver< T, NDIM >::init(), madness::SCF::initial_guess(), madness::Solver< T, NDIM >::initial_guess(), initial_loadbal(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::is_io_node(), iterate(), iterate_excite(), iterate_ground(), iterate_xy(), line_plot(), load_balance(), madness::LoadBalanceDeux< NDIM >::load_balance(), madness::load_coeffs(), load_function(), madness::ElectronPair::load_pair(), madness::GTHPseudopotential< double >::load_pseudo_from_file(), madness::load_quadrature(), loadbal(), SCF::localize_boys(), main(), madness::SCF::make_bsh_operators(), madness::Solver< T, NDIM >::make_bsh_operators(), madness::Solver< T, NDIM >::make_nuclear_charge_density_impl(), madness::Solver< T, NDIM >::make_nuclear_potential(), madness::FunctionImpl< Q, NDIM >::make_Vphi(), moments(), madness::MP2::MP2(), madness::FunctionImpl< Q, NDIM >::multiply(), madness::FunctionImpl< Q, NDIM >::mulXX(), madness::FunctionImpl< Q, NDIM >::mulXXvec(), madness::FunctionImpl< Q, NDIM >::mulXXveca(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::my_io_node(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::open(), madness::FunctionImpl< T, NDIM >::recursive_apply_op< opT, LDIM >::operator()(), madness::FunctionImpl< T, NDIM >::recursive_apply_op2< opT >::operator()(), madness::SCF::orthonormalize(), madness::plot_along(), madness::plot_line(), madness::plot_plane(), madness::plotdx(), madness::plotvtk_begin(), madness::plotvtk_data(), madness::plotvtk_end(), preloadbal(), madness::WorldProfile::print(), madness::Solver< T, NDIM >::print_fock_matrix_eigs(), madness::MP2::print_info(), madness::Solver< T, NDIM >::print_potential_matrix_eigs(), madness::CIS::print_root(), madness::CIS::print_roots(), madness::print_seq(), madness::print_stats(), print_stats(), print_stats_header(), madness::SeparatedConvolution< T, NDIM >::print_timer(), madness::SCF::project_ao_basis(), madness::FunctionImpl< Q, NDIM >::project_out(), madness::FunctionImpl< Q, NDIM >::project_out2(), projectL(), projectPsi(), propagate(), q_c(), random_proc_not_me(), madness::FunctionImpl< Q, NDIM >::recursive_apply(), madness::FunctionImpl< Q, NDIM >::refine(), madness::Solver< T, NDIM >::reproject(), madness::SeparatedConvolution< T, NDIM >::reset_timer(), madness::TaskInterface::run(), save_function(), scaled_plotvtk_begin(), madness::SCF::SCF(), madness::Solver< T, NDIM >::set_occs2(), set_protocol(), madness::SCF::set_protocol(), madness::TDA::setup(), CoupledPurturbation::solve(), SVPEColloidSolver::solve(), madness::TDA::solve(), solve(), madness::SCF::solve(), madness::Solver< T, NDIM >::solve(), madness::CIS::solve_internal_par(), SVPEColloidSolver::solve_Laplace(), madness::MP2::solve_residual_equations(), madness::CIS::sort_roots(), srand(), madness::startup(), madness::Solver< T, NDIM >::step_restriction(), madness::archive::ArchiveStoreImpl< ParallelOutputArchive, WorldContainer< keyT, valueT > >::store(), madness::ElectronPair::store_pair(), test(), test_adaptive_tree(), test_G_R_vectors(), test_gaussian_num_coeffs(), test_modified(), test_nuclear_energy(), test_nuclear_potential(), test_nuclear_potential2(), test_nuclear_potential3(), test_nuclear_potential_big_unit_cell(), test_recursive_application(), test_U_el(), test_wannier(), trotter(), madness::FunctionImpl< Q, NDIM >::unaryXX(), madness::FunctionImpl< Q, NDIM >::unaryXXvalues(), madness::Subspace< T, NDIM >::update_subspace(), madness::SCF::update_subspace(), madness::Nemo::value(), madness::MP2::value(), World(), madness::archive::ArchiveImpl< ParallelInputArchive, T >::wrap_load(), madness::archive::ArchiveImpl< ParallelInputArchive, archive_array< T > >::wrap_load(), madness::archive::ArchiveImpl< ParallelOutputArchive, T >::wrap_store(), and madness::archive::ArchiveImpl< ParallelOutputArchive, archive_array< T > >::wrap_store().

template<typename T >
uniqueidT madness::World::register_ptr ( T *  ptr)
inline

Associate a local pointer with a universe-wide unique id.

Use the routines register_ptr(), unregister_ptr(), id_from_ptr() and ptr_from_id() to map distributed data structures identified by the unique id to/from process-local data.

!! The pointer will be internally cast to a (void *) so don't attempt to shove member pointers in here.

!! ALL unique objects of any type within a world must presently be created in the same order on all processes so as to provide the uniquess property without global communication.

References id(), std::tr1::T(), and unique_obj_id().

void madness::World::set_user_state ( void *  state)
inline

Sets a pointer to user-managed local state.

Rather than having all remotely invoked actions carry all of their data with them, they can access local state thru their world instance. The user is responsible for consistently managing and freeing this data.

A more PC C++ style would be for the app to put state in a singleton.

ProcessID madness::World::size ( ) const
inline
void madness::World::srand ( unsigned long  seed = 0ul)
inline

References rand(), and rank().

Referenced by World().

uniqueidT madness::World::unique_obj_id ( )
inline

Returns new universe-wide unique ID for objects created in this world. No comms.

You should consider using register_ptr(), unregister_ptr(), id_from_ptr() and ptr_from_id() rather than using this directly.

Currently relies on this being called in the same order on every process within the current world in order to avoid synchronization.

The value objid=0 is guaranteed to be invalid.

Referenced by register_ptr().

template<typename T >
void madness::World::unregister_ptr ( T *  ptr)
inline

Unregister a unique id for a local pointer.

References id_from_ptr().

Referenced by madness::WorldObject< DerivativeBase< T, NDIM > >::~WorldObject().

template<typename T >
void madness::World::unregister_ptr ( const uniqueidT  id)
inline

Unregister a unique id for a local pointer based on id.

Same as world.unregister_ptr(world.ptr_from_id<T>(id));

References id(), and std::tr1::T().

static World* madness::World::world_from_id ( unsigned long  id)
inlinestatic

Convert world id to world pointer.

The id will only be valid if the process calling this routine is a member of that world. Thus a null return value does not necessarily mean the world does not exist — it could just not include the calling process.

Parameters
idThe world id
Returns
A pointer to the world associated with id

References id().

Referenced by madness::AmArg::get_world(), madness::archive::ArchiveLoadImpl< BufferInputArchive, WorldObject< Derived > * >::load(), madness::archive::ArchiveLoadImpl< Archive, World * >::load(), madness::archive::ArchiveLoadImpl< BufferInputArchive, const WorldObject< Derived > * >::load(), madness::archive::ArchiveLoadImpl< Archive, const FunctionImpl< T, NDIM > * >::load(), madness::archive::ArchiveLoadImpl< Archive, FunctionImpl< T, NDIM > * >::load(), and madness::detail::WorldPtr< madness::detail::RemoteCounterBase >::load_internal_().

Friends And Related Function Documentation

void finalize ( )
friend

Call this once at the very end of your main program instead of calling MPI_Finalize.

World& initialize ( int &  ,
char **&  ,
const SafeMPI::Intracomm  
)
friend

Initialize the MADNESS runtime.

Call this once at the very top of your main program to initialize the MADNESS runtime. Call this function instead of MPI_Init() or MPI_Init_thread() .

Parameters
argcApplication argument count
argvApplication argument values
commThe communicator that should be used to construct the default World object.
Returns
A reference to the default world which is constructed with comm .
friend class WorldAmInterface
friend
friend class WorldGopInterface
friend

Member Data Documentation

WorldAmInterface& madness::World::am
WorldGopInterface& madness::World::gop

Global operations.

Referenced by madness::add(), madness::apply(), madness::FunctionImpl< Q, NDIM >::apply(), madness::FunctionImpl< Q, NDIM >::apply_1d_realspace_push(), SCF::apply_potential(), madness::GTHPseudopotential< double >::apply_potential(), madness::SCF::apply_potential(), madness::FunctionImpl< Q, NDIM >::apply_source_driven(), madness::FunctionImpl< Q, NDIM >::binaryXX(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::broadcast(), madness::Solver< T, NDIM >::build_fock_matrix(), madness::Function< double, 6 >::clear(), madness::CompositeFunctorInterface< T, NDIM, MDIM >::CompositeFunctorInterface(), madness::compress(), madness::SCF::compute_residual(), madness::Solver< T, NDIM >::compute_rho(), madness::Solver< T, NDIM >::compute_rho_slow(), madness::conj(), madness::TDA_DFT::convolution_with_kernel(), madness::copy(), madness::FunctionImpl< Q, NDIM >::copy_coeffs(), madness::DistributedMatrix< double >::copy_to_replicated(), madness::DistributedMatrix< double >::copy_to_replicated_patch(), CubicInterpolationTable< complexd >::CubicInterpolationTable(), SCF::diag_fock_matrix(), madness::SCF::do_step_restriction(), doit(), energy(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::exists(), madness::BinSorter< T, inserterT >::finish(), madness::FunctionImpl< Q, NDIM >::flo_unary_op_node_inplace(), madness::FunctionImpl< Q, NDIM >::FunctionImpl(), madness::gaxpy(), madness::FunctionImpl< Q, NDIM >::gaxpy(), gaxpy1(), madness::FunctionImpl< Q, NDIM >::gaxpy_ext(), madness::FunctionImpl< Q, NDIM >::gaxpy_inplace(), madness::FunctionImpl< Q, NDIM >::gaxpy_inplace_reconstructed(), madness::SCF::get_fock_transformation(), madness::FunctionImpl< Q, NDIM >::hartree_product(), madness::Solver< T, NDIM >::init(), initial_loadbal(), madness::inner(), line_plot(), madness::FunctionImpl< Q, NDIM >::load(), madness::archive::ArchiveLoadImpl< ParallelInputArchive, WorldContainer< keyT, valueT > >::load(), madness::LoadBalanceDeux< NDIM >::load_balance(), madness::load_coeffs(), madness::SCF::load_mos(), madness::Solver< T, NDIM >::load_orbitals(), madness::load_quadrature(), loadbal(), madness::SCF::loadbal(), madness::LoadBalanceDeux< NDIM >::LoadBalanceDeux(), SCF::localize_boys(), main(), madness::SCF::make_density(), madness::FunctionImpl< Q, NDIM >::make_Vphi(), madness::matrix_inner(), madness::FunctionImpl< Q, NDIM >::merge_trees(), madness::MP2::MP2(), madness::mul(), madness::mul_sparse(), madness::EigSolverOp< T, NDIM >::multi_op_o(), madness::EigSolverOp< T, NDIM >::multi_op_r(), madness::Function< double, 6 >::multiop_values(), madness::FunctionImpl< Q, NDIM >::multiop_values(), madness::FunctionImpl< Q, NDIM >::mulXX(), madness::FunctionImpl< Q, NDIM >::mulXXvec(), madness::nonstandard(), madness::norm2(), madness::norm2s(), madness::norm_tree(), madness::normalize(), madness::archive::BaseParallelArchive< BinaryFstreamInputArchive >::open(), madness::Projector< double, 3 >::operator()(), madness::vecfunc< T, NDIM >::operator*(), madness::xfunction::operator*(), madness::plot_along(), madness::plot_line(), madness::plotdx(), madness::plotvtk_begin(), madness::plotvtk_data(), madness::plotvtk_end(), preloadbal(), madness::WorldProfile::print(), madness::Solver< T, NDIM >::print_fock_matrix_eigs(), madness::Solver< T, NDIM >::print_potential_matrix_eigs(), madness::print_stats(), madness::SCF::project(), madness::SCF::project_ao_basis(), madness::Solver< T, NDIM >::project_ao_basis(), madness::FunctionImpl< Q, NDIM >::project_out(), projectL(), propagate(), madness::reconstruct(), madness::FunctionImpl< Q, NDIM >::recursive_apply(), madness::WorldDCPmapInterface< Key< D > >::redistribute(), madness::FunctionImpl< Q, NDIM >::refine(), madness::Solver< T, NDIM >::reproject(), madness::scale(), madness::FunctionImpl< Q, NDIM >::scale_oop(), scaled_plotvtk_begin(), madness::SCF::SCF(), madness::set_thresh(), madness::SCF::solve(), madness::standard(), madness::START_TIMER(), START_TIMER(), madness::Solver< T, NDIM >::START_TIMER(), madness::startup(), madness::FunctionImpl< Q, NDIM >::store(), madness::archive::ArchiveStoreImpl< ParallelOutputArchive, WorldContainer< keyT, valueT > >::store(), madness::sub(), madness::TDA_DFT::TDA_DFT(), test(), madness::transform(), madness::truncate(), SCF::twoint(), madness::SCF::twoint(), madness::FunctionImpl< Q, NDIM >::unary_op_coeff_inplace(), madness::FunctionImpl< Q, NDIM >::unary_op_node_inplace(), madness::FunctionImpl< Q, NDIM >::unary_op_value_inplace(), madness::FunctionImpl< Q, NDIM >::unaryXX(), madness::FunctionImpl< Q, NDIM >::unaryXXvalues(), madness::Subspace< T, NDIM >::update_subspace(), madness::SCF::update_subspace(), madness::FunctionImpl< Q, NDIM >::vtransform(), World(), and ~World().

WorldMpiInterface& madness::World::mpi
WorldTaskQueue& madness::World::taskq

The documentation for this class was generated from the following files: