iterative-solver 0.0
 
Loading...
Searching...
No Matches
molpro::linalg::array::DistrArrayFile Class Reference

Distributed array storing the buffer on disk using temporary local files. More...

#include <DistrArrayFile.h>

Inheritance diagram for molpro::linalg::array::DistrArrayFile:
Collaboration diagram for molpro::linalg::array::DistrArrayFile:

Detailed Description

Distributed array storing the buffer on disk using temporary local files.

On construction, file and corresponding stream object are created and file is then closed. On destruction, file is deleted.

Warning
Only local operations will be currently supported, if RMA operations are requested, exception will be thrown.
Examples
LinearEigensystemDistrArrayExample.cpp, and OptimizeDistrArrayExample.cpp.

Public Member Functions

 DistrArrayFile ()=delete
 returns local array boundaries and size
 
 DistrArrayFile (const DistrArrayFile &source)
 Creates a copy of source, with its file in the directory of the file of source.
 
 DistrArrayFile (DistrArrayFile &&source)
 
 DistrArrayFile (size_t dimension, MPI_Comm comm=molpro::mpi::comm_global(), const std::string &directory=".")
 
 DistrArrayFile (std::unique_ptr< Distribution > distribution, MPI_Comm comm=molpro::mpi::comm_global(), const std::string &directory=".")
 
 DistrArrayFile (const DistrArray &source)
 
DistrArrayFile & operator= (const DistrArrayFile &source)=delete
 
DistrArrayFile & operator= (DistrArrayFile &&source) noexcept
 
 ~DistrArrayFile () override
 
std::string file_directory () const override
 The directory of the file holding this array, or an empty string if that is not known.
 
bool compatible (const DistrArrayFile &source) const
 
void erase () override
 Dummy.
 
value_type at (index_type ind) const override
 
void set (index_type ind, value_type val) override
 Writes value at a given index.
 
void get (index_type lo, index_type hi, value_type *buf) const override
 Reads requested values.
 
std::vector< value_type > get (index_type lo, index_type hi) const override
 
void put (index_type lo, index_type hi, const value_type *data) override
 Writes requested values to file.
 
void acc (index_type lo, index_type hi, const value_type *data) override
 
std::vector< value_type > gather (const std::vector< index_type > &indices) const override
 gets elements with discontinuous indices from array. Blocking
 
void scatter (const std::vector< index_type > &indices, const std::vector< value_type > &data) override
 array[indices[i]] = data[i] Puts vals of elements with discontinuous indices of array. Blocking.
 
void scatter_acc (std::vector< index_type > &indices, const std::vector< value_type > &data) override
 array[indices[i]] += vals[i] Accumulates vals of elements into discontinuous indices of array. Atomic, blocking, with on-sided communication
 
std::vector< value_type > vec () const override
 Copies the whole buffer into a vector. Blocking.
 
- Public Member Functions inherited from molpro::linalg::array::DistrArrayDisk
const Distribution & distribution () const override
 Access distribution of the array among processes.
 
value_type dot (const DistrArrayDisk &y) const
 
void set_buffer_size (size_t buffer_size)
 
size_t disk_page_size () const override
 
std::unique_ptr< LocalBuffer > local_buffer () override
 Not available: an array on disk is not held in memory.
 
std::unique_ptr< const LocalBuffer > local_buffer () const override
 Not available: an array on disk is not held in memory.
 
value_type dot (Span< const value_type > y) const
 Scalar product <this|y>. Collective, the result is available to each process.
 
virtual value_type dot (const DistrArray &y) const
 Scalar product of two arrays. Collective. Throws error if any array is empty. Both arrays should be part of the same processor group (same communicator). The result is broadcast to each process.
 
virtual value_type dot (const SparseArray &y) const
 
- Public Member Functions inherited from molpro::linalg::array::DistrArray
virtual ~DistrArray ()=default
 
 DistrArray (const DistrArray &)=default
 
 DistrArray (DistrArray &&) noexcept=default
 
DistrArray & operator= (const DistrArray &)=default
 
DistrArray & operator= (DistrArray &&) noexcept=default
 
MPI_Comm communicator () const
 return a copy of the communicator
 
virtual void sync () const
 Synchronizes all process in this group and ensures any outstanding operations on the array have completed.
 
size_t size () const
 total number of elements, same as overall dimension of array
 
bool compatible (const DistrArray &other) const
 Checks that arrays are of the same dimensionality.
 
virtual void zero ()
 Set all local elements to zero.
 
virtual void error (const std::string &message) const
 stops application with an error
 
value_type operator[] (index_type ind) const
 
util::ValueProxy< DistrArray > operator[] (index_type ind)
 
virtual void fill (value_type val)
 
virtual void copy (const DistrArray &y)
 
virtual void copy_patch (const DistrArray &y, index_type start, index_type end)
 Copies elements in a patch of y. If both arrays are empty than does nothing. If only one is empty, throws an error.
 
virtual void axpy (value_type a, const DistrArray &y)
 this[:] += a * y[:]. Throws an error if any array is empty. Add a multiple of another array to this one. Blocking, collective.
 
virtual void axpy (value_type a, const SparseArray &y)
 
void copy (const SparseArray &y)
 this[:] = y[:], i.e. the elements of y, and zero elsewhere. Local, each process sets its local section.
 
virtual void scal (value_type a)
 
virtual void add (const DistrArray &y)
 Add another array to this. Local. Throws error if any array is empty.
 
virtual void add (value_type a)
 Add a constant. Local.
 
virtual void sub (const DistrArray &y)
 Subtract another array from this. Local. Throws error if any array is empty.
 
virtual void sub (value_type a)
 Subtract a constant. Local.
 
virtual void recip ()
 Take element-wise reciprocal of this. Local. No checks are made for zero values.
 
virtual void times (const DistrArray &y)
 this[i] *= y[i]. Throws error if any array is empty.
 
virtual void times (const DistrArray &y, const DistrArray &z)
 this[i] = y[i]*z[i]. Throws error if any array is empty.
 
void copy (Span< const value_type > y)
 
void axpy (value_type a, Span< const value_type > y)
 this[:] += a * y[:] over the local section. Local.
 
void copy_to (Span< value_type > y) const
 y[:] = this[:]. Collective: each process copies its local section, and then y is replicated over all of them.
 
void axpy_to (value_type a, Span< value_type > y) const
 
value_type dot (Span< const value_type > y) const
 Scalar product <this|y>. Collective, the result is available to each process.
 
std::map< size_t, value_type > select_max_dot (size_t n, Span< const value_type > y) const
 The n indices with the largest |this[i]*y[i]|. Collective.
 
void divide (const DistrArray &y, const DistrArray &z, value_type shift=0, bool append=false, bool negative=false)
 this[i] = y[i]/(z[i]+shift). Collective. Throws error if any array is empty.
 
std::list< std::pair< index_type, value_type > > min_n (int n) const
 returns n smallest elements in array x Collective operation, must be called by all processes in the group.
 
std::list< std::pair< index_type, value_type > > max_n (int n) const
 returns n largest elements in array x Collective operation, must be called by all processes in the group.
 
std::list< std::pair< index_type, value_type > > min_abs_n (int n) const
 returns n elements that are largest by absolute value in array x Collective operation, must be called by all processes in the group.
 
std::list< std::pair< index_type, value_type > > max_abs_n (int n) const
 returns n elements that are largest by absolute value in array x Collective operation, must be called by all processes in the group.
 
std::vector< index_type > min_loc_n (int n) const
 find the index of n smallest components in array x Collective operation, must be called by all processes in the group.
 
std::map< size_t, value_type > select_max_dot (size_t n, const DistrArray &y) const
 
std::map< size_t, value_type > select_max_dot (size_t n, const SparseArray &y) const
 
std::map< size_t, value_type > select (size_t n, bool max=false, bool ignore_sign=false) const
 

Static Public Member Functions

static DistrArrayFile CreateTempCopy (const DistrArray &source, const std::string &directory="")
 Creates a copy of source, with the same distribution and communicator, in a file which is erased on destruction.
 
static DistrArrayFile CreateTempCopy (Span< const value_type > source, MPI_Comm comm, const std::string &directory=".")
 Creates a copy of a contiguous array in a file which is erased on destruction.
 
- Static Public Member Functions inherited from molpro::linalg::array::DistrArrayDisk
static std::string temp_copy_directory (const DistrArray &source, const std::string &directory)
 The directory for the file of a temporary copy of source.
 

Friends

void swap (DistrArrayFile &x, DistrArrayFile &y) noexcept
 

Additional Inherited Members

- Public Types inherited from molpro::linalg::array::DistrArrayDisk
using disk_array = void
 a compile time tag that this is a distributed disk array
 
- Public Types inherited from molpro::linalg::array::DistrArray
using distributed_array = void
 a compile time tag that this is a distributed array
 
using value_type = double
 
using index_type = size_t
 
using SparseArray = std::map< index_type, double >
 
using Distribution = util::Distribution< index_type >
 
- Protected Member Functions inherited from molpro::linalg::array::DistrArrayDisk
 DistrArrayDisk (std::unique_ptr< Distribution > distr, MPI_Comm commun)
 
 DistrArrayDisk ()
 
 DistrArrayDisk (const DistrArray &source)
 
 DistrArrayDisk (DistrArrayDisk &&source) noexcept
 
 ~DistrArrayDisk () override
 
 DistrArray (size_t dimension, MPI_Comm commun)
 Initializes array without allocating any memory.
 
 DistrArray ()=default
 
 DistrArray (const DistrArray &)=default
 
 DistrArray (DistrArray &&) noexcept=default
 
- Protected Member Functions inherited from molpro::linalg::array::DistrArray
 DistrArray (size_t dimension, MPI_Comm commun)
 Initializes array without allocating any memory.
 
 DistrArray ()=default
 
void check_compatible (Span< const value_type > y, const std::string &name) const
 Stops with an error unless the contiguous array y has as many elements as this.
 
virtual void _divide (const DistrArray &y, const DistrArray &z, value_type shift, bool append, bool negative)
 
- Protected Attributes inherited from molpro::linalg::array::DistrArrayDisk
bool m_allocated = false
 Flags that the memory view buffer has been allocated.
 
std::unique_ptr< Distribution > m_distribution
 describes distribution of array among processes
 
size_t m_buffer_size = 8192
 buffer size for paged access via BufferManager
 
- Protected Attributes inherited from molpro::linalg::array::DistrArray
index_type m_dimension = 0
 number of elements in the array
 
MPI_Comm m_communicator
 

Constructor & Destructor Documentation

◆ DistrArrayFile() [1/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( )
delete

returns local array boundaries and size

◆ DistrArrayFile() [2/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( const DistrArrayFile &  source)

Creates a copy of source, with its file in the directory of the file of source.

◆ DistrArrayFile() [3/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( DistrArrayFile &&  source)

◆ DistrArrayFile() [4/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( size_t  dimension,
MPI_Comm  comm = molpro::mpi::comm_global(),
const std::string &  directory = "." 
)
explicit

◆ DistrArrayFile() [5/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( std::unique_ptr< Distribution >  distribution,
MPI_Comm  comm = molpro::mpi::comm_global(),
const std::string &  directory = "." 
)
explicit

◆ DistrArrayFile() [6/6]

molpro::linalg::array::DistrArrayFile::DistrArrayFile ( const DistrArray &  source)
explicit

Creates a copy of source, with its file next to that of source if it is a disk array, otherwise in the current directory

◆ ~DistrArrayFile()

molpro::linalg::array::DistrArrayFile::~DistrArrayFile ( )
override

Member Function Documentation

◆ acc()

void molpro::linalg::array::DistrArrayFile::acc ( DistrArray::index_type  lo,
DistrArray::index_type  hi,
const value_type *  data 
)
overridevirtual
Warning
below functions have to be implemented being pure virtuals, but will return exceptions taken we don't do collectives here

Implements molpro::linalg::array::DistrArray.

◆ at()

DistrArray::value_type molpro::linalg::array::DistrArrayFile::at ( DistrArray::index_type  ind) const
overridevirtual
Returns
element at given index

Implements molpro::linalg::array::DistrArray.

◆ compatible()

bool molpro::linalg::array::DistrArrayFile::compatible ( const DistrArrayFile &  source) const

◆ CreateTempCopy() [1/2]

DistrArrayFile molpro::linalg::array::DistrArrayFile::CreateTempCopy ( const DistrArray &  source,
const std::string &  directory = "" 
)
static

Creates a copy of source, with the same distribution and communicator, in a file which is erased on destruction.

Parameters
sourcearray to be copied
directorydirectory for the file. If empty, the directory of the file of source is used if it is a disk array, otherwise the current directory.

◆ CreateTempCopy() [2/2]

DistrArrayFile molpro::linalg::array::DistrArrayFile::CreateTempCopy ( Span< const value_type >  source,
MPI_Comm  comm,
const std::string &  directory = "." 
)
static

Creates a copy of a contiguous array in a file which is erased on destruction.

Parameters
sourceall elements of the array, the same on every process of comm
commthe processes over which the new array is distributed
directorydirectory for the file

◆ erase()

void molpro::linalg::array::DistrArrayFile::erase ( )
inlineoverridevirtual

◆ file_directory()

std::string molpro::linalg::array::DistrArrayFile::file_directory ( ) const
inlineoverridevirtual

The directory of the file holding this array, or an empty string if that is not known.

Reimplemented from molpro::linalg::array::DistrArrayDisk.

◆ gather()

std::vector< DistrArrayFile::value_type > molpro::linalg::array::DistrArrayFile::gather ( const std::vector< index_type > &  indices) const
overridevirtual

gets elements with discontinuous indices from array. Blocking

Returns
res[i] = array[indices[i]]

Implements molpro::linalg::array::DistrArray.

◆ get() [1/2]

std::vector< DistrArrayFile::value_type > molpro::linalg::array::DistrArrayFile::get ( DistrArray::index_type  lo,
DistrArray::index_type  hi 
) const
overridevirtual
Returns
a vector of values read from file

Implements molpro::linalg::array::DistrArray.

◆ get() [2/2]

void molpro::linalg::array::DistrArrayFile::get ( DistrArray::index_type  lo,
DistrArray::index_type  hi,
DistrArray::value_type *  buf 
) const
overridevirtual

Reads requested values.

Implements molpro::linalg::array::DistrArray.

◆ operator=() [1/2]

DistrArrayFile & molpro::linalg::array::DistrArrayFile::operator= ( const DistrArrayFile &  source)
delete

◆ operator=() [2/2]

DistrArrayFile & molpro::linalg::array::DistrArrayFile::operator= ( DistrArrayFile &&  source)
noexcept

◆ put()

void molpro::linalg::array::DistrArrayFile::put ( DistrArray::index_type  lo,
DistrArray::index_type  hi,
const value_type *  data 
)
overridevirtual

Writes requested values to file.

Implements molpro::linalg::array::DistrArray.

◆ scatter()

void molpro::linalg::array::DistrArrayFile::scatter ( const std::vector< index_type > &  indices,
const std::vector< value_type > &  data 
)
overridevirtual

array[indices[i]] = data[i] Puts vals of elements with discontinuous indices of array. Blocking.

Implements molpro::linalg::array::DistrArray.

◆ scatter_acc()

void molpro::linalg::array::DistrArrayFile::scatter_acc ( std::vector< index_type > &  indices,
const std::vector< value_type > &  data 
)
overridevirtual

array[indices[i]] += vals[i] Accumulates vals of elements into discontinuous indices of array. Atomic, blocking, with on-sided communication

Implements molpro::linalg::array::DistrArray.

◆ set()

void molpro::linalg::array::DistrArrayFile::set ( DistrArray::index_type  ind,
DistrArray::value_type  val 
)
overridevirtual

Writes value at a given index.

Implements molpro::linalg::array::DistrArray.

◆ vec()

std::vector< DistrArrayFile::value_type > molpro::linalg::array::DistrArrayFile::vec ( ) const
overridevirtual

Copies the whole buffer into a vector. Blocking.

Note
This is only meant for debugging small arrays!

Implements molpro::linalg::array::DistrArray.

Friends And Related Symbol Documentation

◆ swap

void swap ( DistrArrayFile &  x,
DistrArrayFile &  y 
)
friend