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<size_t> job_;
43  std::deque<size_t> jobID_;
45  std::queue<size_t> unit_;
47  std::queue<const char*> key_;
49  std::queue<char*> buffer_;
51  std::queue<size_t> size_;
53  std::queue<psio_address> start_;
55  std::queue<psio_address*> end_;
57  std::queue<double**> matrix_;
59  std::queue<size_t> row_length_;
61  std::queue<size_t> col_length_;
63  std::queue<size_t> 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  size_t uniqueID_;
79  std::condition_variable condition_;
80 public:
82  AIOHandler(std::shared_ptr<PSIO> psio);
84  ~AIOHandler();
86  void synchronize();
88  size_t read(size_t unit, const char *key, char *buffer, size_t size,
89  psio_address start, psio_address *end);
91  size_t write(size_t unit, const char *key, char *buffer, size_t size,
92  psio_address start, psio_address *end);
94  size_t read_entry(size_t unit, const char *key, char *buffer, size_t size);
96  size_t write_entry(size_t unit, const char *key, char *buffer, size_t size);
113  size_t read_discont(size_t unit, const char *key, double **matrix,
114  size_t row_length, size_t col_length, size_t col_skip, psio_address start);
116  size_t write_discont(size_t unit, const char *key, double **matrix,
117  size_t row_length, size_t col_length, size_t col_skip, psio_address start);
118 
123  size_t zero_disk(size_t unit, const char* key, size_t rows, size_t cols);
124 
130  size_t write_iwl(size_t 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(size_t jobid);
139 };
140 
141 }
142 
143 #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:166
std::deque< size_t > jobID_
Unique job ID to check for job completion. Should NEVER be 0.
Definition: aiohandler.h:43
std::queue< size_t > col_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:61
std::queue< int > lastbuf_
For IWL: is this the last buffer ?
Definition: aiohandler.h:67
std::queue< size_t > size_
Size argument.
Definition: aiohandler.h:51
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:193
std::queue< psio_address > start_
Start address argument.
Definition: aiohandler.h:53
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:144
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
void wait_for_job(size_t jobid)
Definition: aio_handler.cc:503
std::queue< int > nints_
For IWL: number of ints in the buffer.
Definition: aiohandler.h:65
std::queue< size_t > row_length_
Size argument for discontinuous I/O.
Definition: aiohandler.h:59
std::queue< size_t > col_skip_
Size argument for discontinuous I/O.
Definition: aiohandler.h:63
Definition: libpsio/config.h:63
std::queue< size_t > unit_
Unit number argument.
Definition: aiohandler.h:45
std::queue< size_t * > address_
For IWL: pointer to current position in file.
Definition: aiohandler.h:69
std::queue< char * > buffer_
Memory buffer argument.
Definition: aiohandler.h:49
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:47
size_t uniqueID_
Latest unique job ID.
Definition: aiohandler.h:77
std::queue< psio_address * > end_
End address pointer argument.
Definition: aiohandler.h:55
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:94
const char * labels[]
Definition: petitelist.cc:1076
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:244
void call_aio()
Generic function bound to thread internally.
Definition: aio_handler.cc:273
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:70
size_t zero_disk(size_t unit, const char *key, size_t rows, size_t cols)
Definition: aio_handler.cc:220
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:58
~AIOHandler()
Destructor.
Definition: aio_handler.cc:53
std::queue< size_t > job_
What is the job type?
Definition: aiohandler.h:41
std::queue< double ** > matrix_
Matrix pointer for discontinuous I/O.
Definition: aiohandler.h:57
Definition: aiohandler.h:38
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:122