[0b990d] | 1 | //
|
---|
| 2 | // r12ia_mpiiofile.h
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2002 Edward Valeev
|
---|
| 5 | //
|
---|
| 6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
|
---|
| 7 | // Maintainer: EV
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
| 12 | // it under the terms of the GNU Library General Public License as published by
|
---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
| 14 | // any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU Library General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU Library General Public License
|
---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | //
|
---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | #ifndef _chemistry_qc_mbptr12_r12ia_mpiiofile_h
|
---|
| 29 | #define _chemistry_qc_mbptr12_r12ia_mpiiofile_h
|
---|
| 30 |
|
---|
| 31 | #ifdef __GNUC__
|
---|
| 32 | #pragma interface
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #define MPICH_SKIP_MPICXX
|
---|
| 36 | #include <mpi.h>
|
---|
| 37 | #include <util/ref/ref.h>
|
---|
| 38 | #include <util/group/memory.h>
|
---|
| 39 | #include <chemistry/qc/mbptr12/r12ia.h>
|
---|
| 40 |
|
---|
| 41 | namespace sc {
|
---|
| 42 |
|
---|
| 43 | //////////////////////////////////////////////////////////////////////////
|
---|
| 44 | // R12IntsAcc_MPIIOFile handles transformed integrals stored in a binary
|
---|
| 45 | // file accessed through MPI-IO. This is an abstract base for MPIIO-based
|
---|
| 46 | // accumulators using individual and collective I/O.
|
---|
| 47 | //
|
---|
| 48 | // The ordering of integrals in blocks is not specified
|
---|
| 49 | // to avoid having to reorder integrals
|
---|
| 50 | // Each pair block has size of num_te_types*nbasis1*nbasis2
|
---|
| 51 |
|
---|
| 52 | class R12IntsAcc_MPIIOFile: public R12IntsAcc {
|
---|
| 53 |
|
---|
| 54 | protected:
|
---|
| 55 | Ref<MemoryGrp> mem_; // The MemoryGrp associated with this accumulator
|
---|
| 56 | int nproc_;
|
---|
| 57 | size_t nints_per_block_; // number of integrals per block = num_te_types*nbasis__2_
|
---|
| 58 | char *filename_;
|
---|
| 59 | MPI_File datafile_;
|
---|
| 60 |
|
---|
| 61 | struct PairBlkInfo {
|
---|
| 62 | double* ints_[max_num_te_types_]; // blocks corresponding to each operator type
|
---|
| 63 | int refcount_[max_num_te_types_]; // number of references
|
---|
| 64 | MPI_Offset offset_; // location in file (in bytes)
|
---|
| 65 | } *pairblk_;
|
---|
| 66 |
|
---|
| 67 | /// Utility function to check MPI I/O error codes.
|
---|
| 68 | void check_error_code_(int errcod) const;
|
---|
| 69 | // Initialization tasks common to all constructors
|
---|
| 70 | void init(bool restart);
|
---|
| 71 |
|
---|
| 72 | /// total number of tasks
|
---|
| 73 | int ntasks() const { return mem_->n(); }
|
---|
| 74 | /// ID of this task
|
---|
| 75 | int taskid() const { return mem_->me(); }
|
---|
| 76 |
|
---|
| 77 | public:
|
---|
| 78 | R12IntsAcc_MPIIOFile(Ref<MemoryGrp>& mem, const char *filename, int num_te_types,
|
---|
| 79 | int ni, int nj, int nx, int ny);
|
---|
| 80 | R12IntsAcc_MPIIOFile(StateIn&);
|
---|
| 81 | ~R12IntsAcc_MPIIOFile();
|
---|
| 82 | void save_data_state(StateOut&);
|
---|
| 83 |
|
---|
| 84 | /// Stores an ij pair block of integrals to the file
|
---|
| 85 | void store_pair_block(int i, int j, double *ints);
|
---|
| 86 | /** Commit the content of the accumulator for reading - deactivate the associated MemoryGrp
|
---|
| 87 | and activate the accumulator. This is a collective operation. */
|
---|
| 88 | void commit();
|
---|
| 89 | /// Call when ready to read content
|
---|
| 90 | void activate();
|
---|
| 91 | /// Done reading content - activate the associated MemoryGrp
|
---|
| 92 | /// This is a collective operation
|
---|
| 93 | void deactivate();
|
---|
| 94 | /// Releases an ij pair block of integrals
|
---|
| 95 | void release_pair_block(int i, int j, tbint_type oper_type);
|
---|
| 96 | /// Is this block stored locally?
|
---|
| 97 | bool is_local(int i, int j) const { return true;};
|
---|
| 98 | /// In this implementation blocks are available everywhere
|
---|
| 99 | bool is_avail(int i, int j) const { return true;};
|
---|
| 100 | /// Does this task have access to all the integrals?
|
---|
| 101 | bool has_access(int proc) const { return true;};
|
---|
| 102 | /// Can restart MPI-IO-based accumulator
|
---|
| 103 | bool can_restart() const { return true; };
|
---|
| 104 |
|
---|
| 105 | // Utility functions
|
---|
| 106 | int ij_index(int i, int j) const { return i*nj_ + j; };
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 110 | // R12IntsAcc_MPIIOFile_Ind handles transformed integrals stored in a binary
|
---|
| 111 | // file accessed through MPI-IO individual I/O routines.
|
---|
| 112 | //
|
---|
| 113 | // The ordering of integrals in blocks is not specified
|
---|
| 114 | // to avoid having to reorder integrals
|
---|
| 115 | // Each pair block has size of num_te_types*nbasis*nbasis
|
---|
| 116 |
|
---|
| 117 | class R12IntsAcc_MPIIOFile_Ind: public R12IntsAcc_MPIIOFile {
|
---|
| 118 |
|
---|
| 119 | public:
|
---|
| 120 | R12IntsAcc_MPIIOFile_Ind(Ref<MemoryGrp>& mem, const char *filename, int num_te_types,
|
---|
| 121 | int ni, int nj, int nx, int ny);
|
---|
| 122 | R12IntsAcc_MPIIOFile_Ind(StateIn&);
|
---|
| 123 | ~R12IntsAcc_MPIIOFile_Ind();
|
---|
| 124 | void save_data_state(StateOut&);
|
---|
| 125 |
|
---|
| 126 | /** Stores all pair block of integrals held in mem.
|
---|
| 127 | By default blocks are appended to the end of the same file, i.e.
|
---|
| 128 | they are assumed to have come from consecutive passes of
|
---|
| 129 | the same transformation.
|
---|
| 130 | This is a collective operation.
|
---|
| 131 | See documentation for R12IntsAcc::store_memorygrp()
|
---|
| 132 | for more info.
|
---|
| 133 | */
|
---|
| 134 | void store_memorygrp(Ref<MemoryGrp>& mem, int ni, const size_t blksize = 0);
|
---|
| 135 | /// Retrieves an ij pair block of integrals from the file
|
---|
| 136 | double* retrieve_pair_block(int i, int j, tbint_type oper_type);
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
| 143 | // Local Variables:
|
---|
| 144 | // mode: c++
|
---|
| 145 | // c-file-style: "CLJ"
|
---|
| 146 | // End:
|
---|