Psi4
aiohandler.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef AIOHANDLER_H
30 #define AIOHANDLER_H
31 
32 #include <thread>
33 #include <mutex>
34 #include <condition_variable>
35 
36 namespace psi {
37 
38 class AIOHandler {
39 private:
41  std::queue<unsigned int> job_;
43  std::deque<unsigned long int> jobID_;
45  std::queue<unsigned int> unit_;
47  std::queue<const char*> key_;
49  std::queue<char*> buffer_;
51  std::queue<ULI> size_;
53  std::queue<psio_address> start_;
55  std::queue<psio_address*> end_;
57  std::queue<double**> matrix_;
59  std::queue<ULI> row_length_;
61  std::queue<ULI> col_length_;
63  std::queue<ULI> col_skip_;
65  std::queue<int> nints_;
67  std::queue<int> lastbuf_;
69  std::queue<size_t*> address_;
71  std::shared_ptr<PSIO> psio_;
73  std::shared_ptr<std::thread> thread_;
75  std::mutex *locked_;
77  unsigned long int uniqueID_;
79  std::condition_variable condition_;
80 public:
82  AIOHandler(std::shared_ptr<PSIO> psio);
84  ~AIOHandler();
86  void synchronize();
88  unsigned long int read(unsigned int unit, const char *key, char *buffer, ULI size,
89  psio_address start, psio_address *end);
91  unsigned long int write(unsigned int unit, const char *key, char *buffer, ULI size,
92  psio_address start, psio_address *end);
94  unsigned long int read_entry(unsigned int unit, const char *key, char *buffer, ULI size);
96  unsigned long int write_entry(unsigned int unit, const char *key, char *buffer, ULI size);
113  unsigned long read_discont(unsigned int unit, const char *key, double **matrix,
114  ULI row_length, ULI col_length, ULI col_skip, psio_address start);
116  unsigned long write_discont(unsigned int unit, const char *key, double **matrix,
117  ULI row_length, ULI col_length, ULI col_skip, psio_address start);
118 
123  unsigned long zero_disk(unsigned int unit, const char* key, ULI rows, ULI cols);
124 
130  unsigned long write_iwl(unsigned int unit, const char* key, size_t nints,
131  int lastbuf, char* labels, char* values, size_t labsize,
132  size_t valsize, size_t* address);
134  void call_aio();
135 
138  void wait_for_job(unsigned long int jobid);
139 };
140 
141 }
142 
143 #endif // AIOHANDLER_H
std::queue< int > lastbuf_
For IWL: is this the last buffer ?
Definition: aiohandler.h:67
std::queue< psio_address > start_
Start address argument.
Definition: aiohandler.h:53
unsigned long write_iwl(unsigned int unit, const char *key, size_t nints, int lastbuf, char *labels, char *values, size_t labsize, size_t valsize, size_t *address)
Definition: aio_handler.cc:246
std::mutex * locked_
Lock variable.
Definition: aiohandler.h:75
std::condition_variable condition_
condition variable to wait for a specific job to finish
Definition: aiohandler.h:79
std::shared_ptr< std::thread > thread_
Thread this AIO_Handler is currently running on.
Definition: aiohandler.h:73
std::queue< int > nints_
For IWL: number of ints in the buffer.
Definition: aiohandler.h:65
Definition: libpsio/config.h:65
std::queue< size_t * > address_
For IWL: pointer to current position in file.
Definition: aiohandler.h:69
unsigned long int ULI
Definition: tensors.h:46
unsigned long int read_entry(unsigned int unit, const char *key, char *buffer, ULI size)
Asynchronous read_entry, same as PSIO::read_entry, but nonblocking.
Definition: aio_handler.cc:124
std::queue< unsigned int > job_
What is the job type?
Definition: aiohandler.h:41
std::queue< char * > buffer_
Memory buffer argument.
Definition: aiohandler.h:49
std::queue< unsigned int > unit_
Unit number argument.
Definition: aiohandler.h:45
void wait_for_job(unsigned long int jobid)
Definition: aio_handler.cc:505
std::queue< const char * > key_
Entry Key (80-char) argument.
Definition: aiohandler.h:47
AIOHandler(std::shared_ptr< PSIO > psio)
AIO_Handlers are constructed around a synchronous PSIO object.
Definition: aio_handler.cc:49
std::queue< ULI > col_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:61
std::queue< ULI > col_skip_
Size argument for discontinuous I/O.
Definition: aiohandler.h:63
unsigned long read_discont(unsigned int unit, const char *key, double **matrix, ULI row_length, ULI col_length, ULI col_skip, psio_address start)
Definition: aio_handler.cc:168
unsigned long zero_disk(unsigned int unit, const char *key, ULI rows, ULI cols)
Definition: aio_handler.cc:222
unsigned long int write(unsigned int unit, const char *key, char *buffer, ULI size, psio_address start, psio_address *end)
Asynchronous write, same as PSIO::write, but nonblocking.
Definition: aio_handler.cc:96
std::queue< psio_address * > end_
End address pointer argument.
Definition: aiohandler.h:55
const char * labels[]
Definition: petitelist.cc:1076
unsigned long write_discont(unsigned int unit, const char *key, double **matrix, ULI row_length, ULI col_length, ULI col_skip, psio_address start)
Same as read_discont, but for writing.
Definition: aio_handler.cc:195
std::queue< ULI > size_
Size argument.
Definition: aiohandler.h:51
void call_aio()
Generic function bound to thread internally.
Definition: aio_handler.cc:275
unsigned long int read(unsigned int unit, const char *key, char *buffer, ULI size, psio_address start, psio_address *end)
Asynchronous read, same as PSIO::read, but nonblocking.
Definition: aio_handler.cc:72
std::queue< ULI > row_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:59
std::shared_ptr< PSIO > psio_
PSIO object this AIO_Handler is built on.
Definition: aiohandler.h:71
void synchronize()
When called, synchronize will not return until all requested data has been read or written...
Definition: aio_handler.cc:60
~AIOHandler()
Destructor.
Definition: aio_handler.cc:55
std::deque< unsigned long int > jobID_
Unique job ID to check for job completion. Should NEVER be 0.
Definition: aiohandler.h:43
std::queue< double ** > matrix_
Matrix pointer for discontinuous I/O.
Definition: aiohandler.h:57
unsigned long int write_entry(unsigned int unit, const char *key, char *buffer, ULI size)
Asynchronous read_entry, same as PSIO::write_entry, but nonblocking.
Definition: aio_handler.cc:146
Definition: aiohandler.h:38
unsigned long int uniqueID_
Latest unique job ID.
Definition: aiohandler.h:77