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-2018 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 <condition_variable>
33 #include <mutex>
34 #include <queue>
35 #include <thread>
36 
37 #include "config.h"
38 
39 namespace psi {
40 
41 class PSIO;
42 
43 class AIOHandler {
44  private:
46  std::queue<size_t> job_;
48  std::deque<size_t> jobID_;
50  std::queue<size_t> unit_;
52  std::queue<const char *> key_;
54  std::queue<char *> buffer_;
56  std::queue<size_t> size_;
58  std::queue<psio_address> start_;
60  std::queue<psio_address *> end_;
62  std::queue<double **> matrix_;
64  std::queue<size_t> row_length_;
66  std::queue<size_t> col_length_;
68  std::queue<size_t> col_skip_;
70  std::queue<int> nints_;
72  std::queue<int> lastbuf_;
74  std::queue<size_t *> address_;
76  std::shared_ptr<PSIO> psio_;
78  std::shared_ptr<std::thread> thread_;
80  std::mutex *locked_;
82  size_t uniqueID_;
84  std::condition_variable condition_;
85 
86  public:
88  AIOHandler(std::shared_ptr<PSIO> psio);
90  ~AIOHandler();
92  void synchronize();
94  size_t read(size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end);
96  size_t write(size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end);
98  size_t read_entry(size_t unit, const char *key, char *buffer, size_t size);
100  size_t write_entry(size_t unit, const char *key, char *buffer, size_t size);
117  size_t read_discont(size_t unit, const char *key, double **matrix, size_t row_length, size_t col_length,
118  size_t col_skip, psio_address start);
120  size_t write_discont(size_t unit, const char *key, double **matrix, size_t row_length, size_t col_length,
121  size_t col_skip, psio_address start);
122 
127  size_t zero_disk(size_t unit, const char *key, size_t rows, size_t cols);
128 
134  size_t write_iwl(size_t unit, const char *key, size_t nints, int lastbuf, char *labels, char *values,
135  size_t labsize, size_t valsize, size_t *address);
137  void call_aio();
138 
141  void wait_for_job(size_t jobid);
142 };
143 
144 } // namespace psi
145 
146 #endif // AIOHANDLER_H
size_t read_discont(size_t unit, const char *key, double **matrix, size_t row_length, size_t col_length, size_t col_skip, psio_address start)
Definition: aio_handler.cc:159
std::deque< size_t > jobID_
Unique job ID to check for job completion. Should NEVER be 0.
Definition: aiohandler.h:48
std::queue< size_t > col_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:66
std::queue< int > lastbuf_
For IWL: is this the last buffer ?
Definition: aiohandler.h:72
std::queue< size_t > size_
Size argument.
Definition: aiohandler.h:56
size_t write_discont(size_t unit, const char *key, double **matrix, size_t row_length, size_t col_length, size_t col_skip, psio_address start)
Same as read_discont, but for writing.
Definition: aio_handler.cc:184
std::queue< psio_address > start_
Start address argument.
Definition: aiohandler.h:58
size_t write_entry(size_t unit, const char *key, char *buffer, size_t size)
Asynchronous read_entry, same as PSIO::write_entry, but nonblocking.
Definition: aio_handler.cc:138
std::mutex * locked_
Lock variable.
Definition: aiohandler.h:80
std::condition_variable condition_
condition variable to wait for a specific job to finish
Definition: aiohandler.h:84
std::shared_ptr< std::thread > thread_
Thread this AIO_Handler is currently running on.
Definition: aiohandler.h:78
void wait_for_job(size_t jobid)
Definition: aio_handler.cc:468
std::queue< int > nints_
For IWL: number of ints in the buffer.
Definition: aiohandler.h:70
std::queue< size_t > row_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:64
std::queue< size_t > col_skip_
Size argument for discontinuous I/O.
Definition: aiohandler.h:68
std::queue< size_t * > address_
For IWL: pointer to current position in file.
Definition: aiohandler.h:74
Definition: libpsio/config.h:65
std::queue< size_t > unit_
Unit number argument.
Definition: aiohandler.h:50
std::queue< char * > buffer_
Memory buffer argument.
Definition: aiohandler.h:54
AIOHandler(std::shared_ptr< PSIO > psio)
AIO_Handlers are constructed around a synchronous PSIO object.
Definition: aio_handler.cc:47
std::queue< psio_address * > end_
End address pointer argument.
Definition: aiohandler.h:60
std::queue< const char * > key_
Entry Key (80-char) argument.
Definition: aiohandler.h:52
size_t uniqueID_
Latest unique job ID.
Definition: aiohandler.h:82
size_t write(size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end)
Asynchronous write, same as PSIO::write, but nonblocking.
Definition: aio_handler.cc:89
const char * labels[]
Definition: petitelist.cc:958
size_t write_iwl(size_t 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:231
void call_aio()
Generic function bound to thread internally.
Definition: aio_handler.cc:258
size_t read(size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end)
Asynchronous read, same as PSIO::read, but nonblocking.
Definition: aio_handler.cc:65
size_t zero_disk(size_t unit, const char *key, size_t rows, size_t cols)
Definition: aio_handler.cc:209
std::shared_ptr< PSIO > psio_
PSIO object this AIO_Handler is built on.
Definition: aiohandler.h:76
void synchronize()
When called, synchronize will not return until all requested data has been read or written...
Definition: aio_handler.cc:55
~AIOHandler()
Destructor.
Definition: aio_handler.cc:51
std::queue< double ** > matrix_
Matrix pointer for discontinuous I/O.
Definition: aiohandler.h:62
std::queue< size_t > job_
What is the job type?
Definition: aiohandler.h:46
Definition: aiohandler.h:43
size_t read_entry(size_t unit, const char *key, char *buffer, size_t size)
Asynchronous read_entry, same as PSIO::read_entry, but nonblocking.
Definition: aio_handler.cc:117