1 #ifndef MPQC_MPI_TASK_HPP
2 #define MPQC_MPI_TASK_HPP
4 #include "mpqc/mpi.hpp"
5 #include "mpqc/utility/mutex.hpp"
13 #if (defined HAVE_MPI) && !(defined HAVE_ARMCI)
14 #error mpqc::MPI::Task requires ARMCI if using MPI
22 struct Task : boost::noncopyable {
29 : comm_(comm), data_(0)
32 MPQC_ASSERT(comm == MPI_COMM_WORLD);
34 data_.resize(comm_.size());
35 ARMCI_Malloc(&data_[0],
sizeof(T));
44 ARMCI_Free(data_[comm_.rank()]);
49 void reset(
const T &value = T(0)) {
50 mutex::global::lock();
53 if (comm_.rank() == 0) {
54 ARMCI_PutValueInt(value, this->value(), 0);
61 mutex::global::unlock();
67 mutex::global::lock();
69 ARMCI_Rmw(ARMCI_FETCH_AND_ADD, &
next, this->value(), 1, 0);
73 mutex::global::unlock();
79 int i = block*((*this)++);
83 template<
typename Iterator>
84 Iterator
next(Iterator begin, Iterator end) {
87 for (
int i = 0; i < n; ++i) {
98 std::vector< void* > data_;