Debian Codegraph @

packages/rol/adapters/epetra/src/sol/ROL_EpetraBatchManager.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef ROL_EPETRABATCHMANAGER_HPP
11 #define ROL_EPETRABATCHMANAGER_HPP
12
13 #include "ROL_BatchManager.hpp"
14 #include "Epetra_Comm.h"
15
16 namespace ROL {
17
18 template<class Real>
19 class EpetraBatchManager : public BatchManager<Real> {
20 protected:
21 ROL::Ptr<Epetra_Comm> comm_;
22
23 public:
24 virtual ~EpetraBatchManager() {}
25
26 EpetraBatchManager(ROL::Ptr<Epetra_Comm> &comm) : comm_(comm) {}
27
28 int batchID(void) { return comm_->MyPID(); }
29
30 int numBatches(void) { return comm_->NumProc(); }
31
32 void reduceAll(Real* input, Real* output, int dim,
33 const Elementwise::ReductionOp<Real> &r) {
34 int nB = this->numBatches();
35 std::vector<Real> receiveBuffer(nB);
36 comm_->GatherAll(input,&receiveBuffer[0],1);
37 output[0] = r.initialValue();
38 for (int i = 0; i < nB; i++) {
39 r.reduce(receiveBuffer[i],output[0]);
40 }
41 comm_->Broadcast(output,1,0);
42 }
43
44 void sumAll(Real* input, Real* output, int dim) { comm_->SumAll(input,output,dim); }
45
46 void broadcast(Real* input, int cnt, int root) {
47 comm_->Broadcast(input, cnt, root);
48 }
49
50 void barrier(void) {
51 comm_->Barrier();
52 }
53 };
54
55 }
56
57 #endif