1 | #include "grid_algorithm_generic.hpp" |
---|
2 | #include "grid_elements.hpp" |
---|
3 | #include "grid_local_view.hpp" |
---|
4 | #include "grid.hpp" |
---|
5 | #include "algo_types.hpp" |
---|
6 | #include "context.hpp" |
---|
7 | #include "transform_filter.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
10 | { |
---|
11 | |
---|
12 | CGridAlgorithmGeneric::CGridAlgorithmGeneric(CGrid* gridSrc, CGrid* gridDst, int pos, CGenericAlgorithmTransformation* algo) |
---|
13 | : CGridAlgorithm(algo), gridSrc_(gridSrc), gridDst_(gridDst), pos_(pos) |
---|
14 | { |
---|
15 | computeAlgorithm() ; |
---|
16 | } |
---|
17 | |
---|
18 | void CGridAlgorithmGeneric::computeAlgorithm(void) |
---|
19 | { |
---|
20 | CGridLocalElements* gridSrcElements = gridSrc_->getGridLocalElements() ; |
---|
21 | CGridLocalElements* gridDstElements = gridDst_->getGridLocalElements() ; |
---|
22 | |
---|
23 | CGridLocalView* srcView = gridSrcElements->getView(CElementView::WORKFLOW) ; |
---|
24 | CGridLocalView* dstView = gridDstElements->getView(CElementView::WORKFLOW) ; |
---|
25 | MPI_Comm comm = CContext::getCurrent()->getIntraComm() ; |
---|
26 | int commSize = CContext::getCurrent()->getIntraCommSize() ; |
---|
27 | int commRank = CContext::getCurrent()->getIntraCommRank() ; |
---|
28 | |
---|
29 | auto& elements = gridSrcElements->getElements() ; |
---|
30 | int nElements = elements.size() ; |
---|
31 | vector<CLocalElement*> remoteElements(nElements) ; |
---|
32 | vector<CLocalView*> remoteViews(nElements) ; |
---|
33 | for(int i=0;i<nElements;i++) |
---|
34 | { |
---|
35 | if (i==pos_) remoteElements[i] = algorithm_->getRecvElement() ; |
---|
36 | else |
---|
37 | { |
---|
38 | CArray<size_t,1> globalIndexView ; |
---|
39 | srcView->getView(i)->getGlobalIndexView(globalIndexView) ; |
---|
40 | remoteElements[i] = new CLocalElement(commRank, srcView->getView(i)->getGlobalSize(),globalIndexView) ; |
---|
41 | remoteElements[i]->addFullView() ; |
---|
42 | if (i>pos_) dimBefore_ *= srcView->getView(i)->getSize() ; |
---|
43 | else dimAfter_ *= srcView->getView(i)->getSize() ; |
---|
44 | |
---|
45 | } |
---|
46 | remoteViews[i] = remoteElements[i] -> getView(CElementView::FULL); |
---|
47 | } |
---|
48 | |
---|
49 | gridTransformConnector_ = new CGridTransformConnector(srcView->getViews(), remoteViews, comm ) ; |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, CArray<double,1>& dataOut) |
---|
54 | { |
---|
55 | CArray<double,1> dataOutTmp ; |
---|
56 | gridTransformConnector_->transfer(dataIn, dataOutTmp) ; |
---|
57 | algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, dataOut) ; |
---|
58 | } |
---|
59 | |
---|
60 | void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, const vector<CArray<double,1>>& auxData, CArray<double,1>& dataOut) |
---|
61 | { |
---|
62 | CArray<double,1> dataOutTmp ; |
---|
63 | vector<CArray<double,1>> auxDataOutTmp(auxData.size()) ; |
---|
64 | |
---|
65 | gridTransformConnector_->transfer(dataIn, dataOutTmp) ; |
---|
66 | for (int i=0; i<auxData.size();i++) |
---|
67 | { |
---|
68 | if (algorithm_->transformAuxField(i)) gridTransformConnector_->transfer(auxData[i], auxDataOutTmp[i]) ; |
---|
69 | else auxDataOutTmp[i].reference(auxData[i]) ; |
---|
70 | } |
---|
71 | |
---|
72 | algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, auxDataOutTmp, dataOut) ; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | } |
---|