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 program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program 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 General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef AIOHANDLER_H
29 #define AIOHANDLER_H
30 
31 #include <thread>
32 #include <mutex>
33 #include <condition_variable>
34 
35 namespace psi {
36 
37 class AIOHandler {
38 private:
40  std::queue<unsigned int> job_;
42  std::deque<unsigned long int> jobID_;
44  std::queue<unsigned int> unit_;
46  std::queue<const char*> key_;
48  std::queue<char*> buffer_;
50  std::queue<ULI> size_;
52  std::queue<psio_address> start_;
54  std::queue<psio_address*> end_;
56  std::queue<double**> matrix_;
58  std::queue<ULI> row_length_;
60  std::queue<ULI> col_length_;
62  std::queue<ULI> col_skip_;
64  std::queue<int> nints_;
66  std::queue<int> lastbuf_;
68  std::queue<size_t*> address_;
70  std::shared_ptr<PSIO> psio_;
72  std::shared_ptr<std::thread> thread_;
74  std::mutex *locked_;
76  unsigned long int uniqueID_;
78  std::condition_variable condition_;
79 public:
81  AIOHandler(std::shared_ptr<PSIO> psio);
83  ~AIOHandler();
85  void synchronize();
87  unsigned long int read(unsigned int unit, const char *key, char *buffer, ULI size,
88  psio_address start, psio_address *end);
90  unsigned long int write(unsigned int unit, const char *key, char *buffer, ULI size,
91  psio_address start, psio_address *end);
93  unsigned long int read_entry(unsigned int unit, const char *key, char *buffer, ULI size);
95  unsigned long int write_entry(unsigned int unit, const char *key, char *buffer, ULI size);
112  unsigned long read_discont(unsigned int unit, const char *key, double **matrix,
113  ULI row_length, ULI col_length, ULI col_skip, psio_address start);
115  unsigned long write_discont(unsigned int unit, const char *key, double **matrix,
116  ULI row_length, ULI col_length, ULI col_skip, psio_address start);
117 
122  unsigned long zero_disk(unsigned int unit, const char* key, ULI rows, ULI cols);
123 
129  unsigned long write_iwl(unsigned int unit, const char* key, size_t nints,
130  int lastbuf, char* labels, char* values, size_t labsize,
131  size_t valsize, size_t* address);
133  void call_aio();
134 
137  void wait_for_job(unsigned long int jobid);
138 };
139 
140 }
141 
142 #endif // AIOHANDLER_H
std::queue< int > lastbuf_
For IWL: is this the last buffer ?
Definition: aiohandler.h:66
std::queue< psio_address > start_
Start address argument.
Definition: aiohandler.h:52
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:245
std::mutex * locked_
Lock variable.
Definition: aiohandler.h:74
std::condition_variable condition_
condition variable to wait for a specific job to finish
Definition: aiohandler.h:78
std::shared_ptr< std::thread > thread_
Thread this AIO_Handler is currently running on.
Definition: aiohandler.h:72
std::queue< int > nints_
For IWL: number of ints in the buffer.
Definition: aiohandler.h:64
Definition: libpsio/config.h:64
std::queue< size_t * > address_
For IWL: pointer to current position in file.
Definition: aiohandler.h:68
unsigned long int ULI
Definition: libpsio/config.h:62
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:123
std::queue< unsigned int > job_
What is the job type?
Definition: aiohandler.h:40
std::queue< char * > buffer_
Memory buffer argument.
Definition: aiohandler.h:48
std::queue< unsigned int > unit_
Unit number argument.
Definition: aiohandler.h:44
void wait_for_job(unsigned long int jobid)
Definition: aio_handler.cc:504
std::queue< const char * > key_
Entry Key (80-char) argument.
Definition: aiohandler.h:46
AIOHandler(std::shared_ptr< PSIO > psio)
AIO_Handlers are constructed around a synchronous PSIO object.
Definition: aio_handler.cc:48
std::queue< ULI > col_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:60
std::queue< ULI > col_skip_
Size argument for discontinuous I/O.
Definition: aiohandler.h:62
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:167
unsigned long zero_disk(unsigned int unit, const char *key, ULI rows, ULI cols)
Definition: aio_handler.cc:221
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:95
std::queue< psio_address * > end_
End address pointer argument.
Definition: aiohandler.h:54
const char * labels[]
Definition: petitelist.cc:1075
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:194
std::queue< ULI > size_
Size argument.
Definition: aiohandler.h:50
void call_aio()
Generic function bound to thread internally.
Definition: aio_handler.cc:274
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:71
std::queue< ULI > row_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:58
std::shared_ptr< PSIO > psio_
PSIO object this AIO_Handler is built on.
Definition: aiohandler.h:70
void synchronize()
When called, synchronize will not return until all requested data has been read or written...
Definition: aio_handler.cc:59
~AIOHandler()
Destructor.
Definition: aio_handler.cc:54
std::deque< unsigned long int > jobID_
Unique job ID to check for job completion. Should NEVER be 0.
Definition: aiohandler.h:42
std::queue< double ** > matrix_
Matrix pointer for discontinuous I/O.
Definition: aiohandler.h:56
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:145
Definition: aiohandler.h:37
unsigned long int uniqueID_
Latest unique job ID.
Definition: aiohandler.h:76