[2007] | 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" |
---|
[2628] | 8 | #include "timer.hpp" |
---|
[2007] | 9 | |
---|
| 10 | namespace xios |
---|
| 11 | { |
---|
[2628] | 12 | extern CLogType logProfile ; |
---|
[2007] | 13 | |
---|
[2270] | 14 | CGridAlgorithmGeneric::CGridAlgorithmGeneric(CGrid* gridSrc, CGrid* gridDst, int pos, shared_ptr<CGenericAlgorithmTransformation> algo) |
---|
[2007] | 15 | : CGridAlgorithm(algo), gridSrc_(gridSrc), gridDst_(gridDst), pos_(pos) |
---|
| 16 | { |
---|
| 17 | } |
---|
| 18 | |
---|
[2291] | 19 | void CGridAlgorithmGeneric::computeAlgorithm(bool eliminateRedondant) |
---|
[2007] | 20 | { |
---|
[2267] | 21 | shared_ptr<CGridLocalElements> gridSrcElements = gridSrc_->getGridLocalElements() ; |
---|
| 22 | shared_ptr<CGridLocalElements> gridDstElements = gridDst_->getGridLocalElements() ; |
---|
[2007] | 23 | |
---|
[2267] | 24 | shared_ptr<CGridLocalView> srcView = gridSrcElements->getView(CElementView::WORKFLOW) ; |
---|
| 25 | shared_ptr<CGridLocalView> dstView = gridDstElements->getView(CElementView::WORKFLOW) ; |
---|
[2007] | 26 | MPI_Comm comm = CContext::getCurrent()->getIntraComm() ; |
---|
| 27 | int commSize = CContext::getCurrent()->getIntraCommSize() ; |
---|
| 28 | int commRank = CContext::getCurrent()->getIntraCommRank() ; |
---|
| 29 | |
---|
| 30 | auto& elements = gridSrcElements->getElements() ; |
---|
| 31 | int nElements = elements.size() ; |
---|
[2267] | 32 | vector<shared_ptr<CLocalElement>> remoteElements(nElements) ; |
---|
| 33 | vector<shared_ptr<CLocalView>> remoteViews(nElements) ; |
---|
[2007] | 34 | for(int i=0;i<nElements;i++) |
---|
| 35 | { |
---|
| 36 | if (i==pos_) remoteElements[i] = algorithm_->getRecvElement() ; |
---|
| 37 | else |
---|
| 38 | { |
---|
| 39 | CArray<size_t,1> globalIndexView ; |
---|
| 40 | srcView->getView(i)->getGlobalIndexView(globalIndexView) ; |
---|
[2267] | 41 | remoteElements[i] = make_shared<CLocalElement>(commRank, srcView->getView(i)->getGlobalSize(),globalIndexView) ; |
---|
[2007] | 42 | remoteElements[i]->addFullView() ; |
---|
| 43 | if (i>pos_) dimBefore_ *= srcView->getView(i)->getSize() ; |
---|
| 44 | else dimAfter_ *= srcView->getView(i)->getSize() ; |
---|
| 45 | |
---|
| 46 | } |
---|
| 47 | remoteViews[i] = remoteElements[i] -> getView(CElementView::FULL); |
---|
| 48 | } |
---|
| 49 | |
---|
[2267] | 50 | gridTransformConnector_ = make_shared<CGridTransformConnector>(srcView->getViews(), remoteViews, comm ) ; |
---|
[2291] | 51 | gridTransformConnector_->computeConnector(eliminateRedondant) ; |
---|
[2007] | 52 | |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, CArray<double,1>& dataOut) |
---|
| 56 | { |
---|
| 57 | CArray<double,1> dataOutTmp ; |
---|
[2628] | 58 | if (info.isActive(logProfile)) CTimer::get("Transformation transfers").resume() ; |
---|
[2007] | 59 | gridTransformConnector_->transfer(dataIn, dataOutTmp) ; |
---|
[2628] | 60 | if (info.isActive(logProfile)) CTimer::get("Transformation transfers").suspend() ; |
---|
[2007] | 61 | algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, dataOut) ; |
---|
| 62 | } |
---|
| 63 | |
---|
[2011] | 64 | void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, const vector<CArray<double,1>>& auxData, CArray<double,1>& dataOut) |
---|
| 65 | { |
---|
| 66 | CArray<double,1> dataOutTmp ; |
---|
| 67 | vector<CArray<double,1>> auxDataOutTmp(auxData.size()) ; |
---|
[2007] | 68 | |
---|
[2011] | 69 | gridTransformConnector_->transfer(dataIn, dataOutTmp) ; |
---|
[2122] | 70 | for (int i=0; i<auxData.size();i++) |
---|
| 71 | { |
---|
| 72 | if (algorithm_->transformAuxField(i)) gridTransformConnector_->transfer(auxData[i], auxDataOutTmp[i]) ; |
---|
| 73 | else auxDataOutTmp[i].reference(auxData[i]) ; |
---|
| 74 | } |
---|
[2011] | 75 | |
---|
| 76 | algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, auxDataOutTmp, dataOut) ; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
[2628] | 80 | } |
---|