| 1 | //
|
|---|
| 2 | // r12ia_node0file.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_node0file_h
|
|---|
| 29 | #define _chemistry_qc_mbptr12_r12ia_node0file_h
|
|---|
| 30 |
|
|---|
| 31 | #ifdef __GNUC__
|
|---|
| 32 | #pragma interface
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | #include <unistd.h>
|
|---|
| 36 | #include <util/ref/ref.h>
|
|---|
| 37 | #include <util/group/memory.h>
|
|---|
| 38 | #include <chemistry/qc/mbptr12/r12ia.h>
|
|---|
| 39 |
|
|---|
| 40 | namespace sc {
|
|---|
| 41 |
|
|---|
| 42 | /////////////////////////////////////////////////////////////////////
|
|---|
| 43 | // R12IntsAcc_Node0File handles transformed integrals stored in file
|
|---|
| 44 | // on node 0 (file is a usual POSIX binary file)
|
|---|
| 45 | //
|
|---|
| 46 | // Transfering integrals to the file from nodes is done via MemoryGrp
|
|---|
| 47 | // given as an argument to store_memorygrp
|
|---|
| 48 | // Remote retrieval is not possible
|
|---|
| 49 | //
|
|---|
| 50 | // The ordering of integrals in blocks is not specified
|
|---|
| 51 | // to avoid having to reorder integrals
|
|---|
| 52 | // Each pair block has size of num_te_types*nbasis1*nbasis2
|
|---|
| 53 |
|
|---|
| 54 | class R12IntsAcc_Node0File: public R12IntsAcc {
|
|---|
| 55 |
|
|---|
| 56 | Ref<MemoryGrp> mem_; // The MemoryGrp associated with this accumulator
|
|---|
| 57 | char *filename_;
|
|---|
| 58 | int datafile_;
|
|---|
| 59 |
|
|---|
| 60 | struct PairBlkInfo {
|
|---|
| 61 | double* ints_[max_num_te_types_]; // blocks corresponding to each operator type
|
|---|
| 62 | int refcount_[max_num_te_types_]; // number of references
|
|---|
| 63 | off_t offset_; // location in file (in bytes)
|
|---|
| 64 | } *pairblk_;
|
|---|
| 65 |
|
|---|
| 66 | // Initialization tasks common to all constructors
|
|---|
| 67 | void init(bool restart);
|
|---|
| 68 | // Check if the file operation went OK
|
|---|
| 69 | void check_filedescr_();
|
|---|
| 70 |
|
|---|
| 71 | /// total number of tasks
|
|---|
| 72 | int ntasks() const { return mem_->n(); }
|
|---|
| 73 | /// ID of this task
|
|---|
| 74 | int taskid() const { return mem_->me(); }
|
|---|
| 75 |
|
|---|
| 76 | public:
|
|---|
| 77 | R12IntsAcc_Node0File(Ref<MemoryGrp>& mem, const char *filename, int num_te_types, int ni, int nj,
|
|---|
| 78 | int nx, int ny);
|
|---|
| 79 | R12IntsAcc_Node0File(StateIn&);
|
|---|
| 80 | ~R12IntsAcc_Node0File();
|
|---|
| 81 | void save_data_state(StateOut&);
|
|---|
| 82 |
|
|---|
| 83 | /** Stores all pair block of integrals held in mem.
|
|---|
| 84 | By default blocks are appended to the end of the same file, i.e.
|
|---|
| 85 | they are assumed to have come from consecutive passes of
|
|---|
| 86 | the same transformation.
|
|---|
| 87 | This is a collective operation. See documentation for R12IntsAcc::store_memorygrp()
|
|---|
| 88 | for more info.
|
|---|
| 89 | */
|
|---|
| 90 | void store_memorygrp(Ref<MemoryGrp>& mem, int ni, const size_t blksize = 0);
|
|---|
| 91 | /// Stores an ij pair block of integrals to the file
|
|---|
| 92 | void store_pair_block(int i, int j, double *ints);
|
|---|
| 93 | /** Commit the content of the accumulator for reading - deactivate the associated MemoryGrp
|
|---|
| 94 | and activate the accumulator. This is a collective operation. */
|
|---|
| 95 | void commit();
|
|---|
| 96 | /// Call when ready to start reading content
|
|---|
| 97 | void activate();
|
|---|
| 98 | /// Done reading content - activate the associated MemoryGrp
|
|---|
| 99 | /// This is a collective operation
|
|---|
| 100 | void deactivate();
|
|---|
| 101 | /// Retrieves an ij pair block of integrals from the file
|
|---|
| 102 | double* retrieve_pair_block(int i, int j, tbint_type oper_type);
|
|---|
| 103 | /// Releases an ij pair block of integrals
|
|---|
| 104 | void release_pair_block(int i, int j, tbint_type oper_type);
|
|---|
| 105 | /// Is this block stored locally?
|
|---|
| 106 | bool is_local(int i, int j) const { return (mem_->me() == 0);};
|
|---|
| 107 | /// In this implementation blocks are available only on node 0
|
|---|
| 108 | bool is_avail(int i, int j) const { return (mem_->me() == 0);};
|
|---|
| 109 | /// Does this task have access to all the integrals?
|
|---|
| 110 | bool has_access(int proc) const { return (proc == 0);};
|
|---|
| 111 | /// Can restart Node0File-based accumulator
|
|---|
| 112 | bool can_restart() const { return true; };
|
|---|
| 113 |
|
|---|
| 114 | // Utility functions
|
|---|
| 115 | int ij_index(int i, int j) const { return i*nj_ + j; };
|
|---|
| 116 | int ij_proc(int i, int j) const { return 0;};
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | #endif
|
|---|
| 122 |
|
|---|
| 123 | // Local Variables:
|
|---|
| 124 | // mode: c++
|
|---|
| 125 | // c-file-style: "CLJ"
|
|---|
| 126 | // End:
|
|---|