[887] | 1 | #include "scalar.hpp" |
---|
| 2 | |
---|
| 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
| 6 | #include "object_factory.hpp" |
---|
| 7 | #include "xios_spl.hpp" |
---|
| 8 | #include "type.hpp" |
---|
[1930] | 9 | #include "context.hpp" |
---|
[887] | 10 | |
---|
[2203] | 11 | #include <algorithm> |
---|
| 12 | #include <regex> |
---|
| 13 | |
---|
[1940] | 14 | namespace xios |
---|
| 15 | { |
---|
[887] | 16 | |
---|
[1940] | 17 | /// ////////////////////// Définitions ////////////////////// /// |
---|
[887] | 18 | |
---|
[1940] | 19 | CScalar::CScalar(void) |
---|
| 20 | : CObjectTemplate<CScalar>() |
---|
| 21 | , CScalarAttributes() |
---|
| 22 | , relFiles() |
---|
| 23 | { /* Ne rien faire de plus */ } |
---|
[887] | 24 | |
---|
[1940] | 25 | CScalar::CScalar(const StdString & id) |
---|
| 26 | : CObjectTemplate<CScalar>(id) |
---|
| 27 | , CScalarAttributes() |
---|
| 28 | , relFiles() |
---|
| 29 | { /* Ne rien faire de plus */ } |
---|
[887] | 30 | |
---|
[1940] | 31 | CScalar::~CScalar(void) |
---|
| 32 | { /* Ne rien faire de plus */ } |
---|
[887] | 33 | |
---|
[2274] | 34 | void CScalar::releaseStaticAllocation(void) |
---|
| 35 | { |
---|
| 36 | transformationMapList_.clear() ; |
---|
| 37 | CTransformation<CScalar>::unregisterAllTransformations() ; |
---|
| 38 | CGridTransformationFactory<CScalar>::unregisterAllTransformations() ; |
---|
| 39 | } |
---|
| 40 | |
---|
[1940] | 41 | std::map<StdString, ETranformationType> CScalar::transformationMapList_ = std::map<StdString, ETranformationType>(); |
---|
| 42 | bool CScalar::dummyTransformationMapList_ = CScalar::initializeTransformationMap(CScalar::transformationMapList_); |
---|
| 43 | bool CScalar::initializeTransformationMap(std::map<StdString, ETranformationType>& m) |
---|
| 44 | { |
---|
| 45 | m["reduce_axis"] = TRANS_REDUCE_AXIS_TO_SCALAR; |
---|
| 46 | m["extract_axis"] = TRANS_EXTRACT_AXIS_TO_SCALAR; |
---|
| 47 | m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_SCALAR; |
---|
| 48 | m["reduce_scalar"] = TRANS_REDUCE_SCALAR_TO_SCALAR; |
---|
[2461] | 49 | m["redistribute_scalar"] = TRANS_REDISTRIBUTE_SCALAR; |
---|
[2196] | 50 | return true; |
---|
[1940] | 51 | } |
---|
[888] | 52 | |
---|
[1940] | 53 | StdString CScalar::GetName(void) { return (StdString("scalar")); } |
---|
| 54 | StdString CScalar::GetDefName(void){ return (CScalar::GetName()); } |
---|
| 55 | ENodeType CScalar::GetType(void) { return (eScalar); } |
---|
[887] | 56 | |
---|
[1940] | 57 | CScalar* CScalar::createScalar() |
---|
| 58 | { |
---|
| 59 | CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild(); |
---|
| 60 | return scalar; |
---|
| 61 | } |
---|
[887] | 62 | |
---|
[2206] | 63 | CScalar* CScalar::get(const string& id, bool noError) |
---|
[2203] | 64 | { |
---|
| 65 | const regex r("::"); |
---|
| 66 | smatch m; |
---|
| 67 | if (regex_search(id, m, r)) |
---|
| 68 | { |
---|
| 69 | if (m.size()!=1) ERROR("CScalar* CScalar::get(string& id)", <<" id = "<<id<< " -> bad format id, separator :: append more than one time"); |
---|
| 70 | string fieldId=m.prefix() ; |
---|
| 71 | if (fieldId.empty()) ERROR("CScalar* CScalar::get(string& id)", <<" id = "<<id<< " -> bad format id, field name is empty"); |
---|
| 72 | string suffix=m.suffix() ; |
---|
[2206] | 73 | if (!CField::has(fieldId)) |
---|
| 74 | if (noError) return nullptr ; |
---|
| 75 | else ERROR("CScalar* CScalar::get(const string& id, bool noError)", <<" id = "<<id<< " -> field Id : < "<<fieldId<<" > doesn't exist"); |
---|
[2203] | 76 | CField* field=CField::get(fieldId) ; |
---|
[2206] | 77 | return field->getAssociatedScalar(suffix, noError) ; |
---|
[2203] | 78 | } |
---|
[2206] | 79 | else |
---|
| 80 | { |
---|
| 81 | if (noError) if(!CObjectFactory::HasObject<CScalar>(id)) return nullptr ; |
---|
| 82 | return CObjectFactory::GetObject<CScalar>(id).get(); |
---|
| 83 | } |
---|
| 84 | } |
---|
[2203] | 85 | |
---|
[2206] | 86 | bool CScalar::has(const string& id) |
---|
| 87 | { |
---|
| 88 | if (CScalar::get(id,true)==nullptr) return false ; |
---|
| 89 | else return true ; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | CField* CScalar::getFieldFromId(const string& id) |
---|
| 93 | { |
---|
| 94 | const regex r("::"); |
---|
| 95 | smatch m; |
---|
| 96 | if (regex_search(id, m, r)) |
---|
| 97 | { |
---|
| 98 | if (m.size()!=1) ERROR("CField* CScalar::getFieldFromId(const string& id)", <<" id = "<<id<< " -> bad format id, separator :: append more than one time"); |
---|
| 99 | string fieldId=m.prefix() ; |
---|
| 100 | if (fieldId.empty()) ERROR("CField* CScalar::getFieldFromId(const string& id)", <<" id = "<<id<< " -> bad format id, field name is empty"); |
---|
| 101 | string suffix=m.suffix() ; |
---|
| 102 | CField* field=CField::get(fieldId) ; |
---|
| 103 | return field ; |
---|
| 104 | } |
---|
| 105 | else return nullptr; |
---|
| 106 | } |
---|
| 107 | |
---|
[1940] | 108 | bool CScalar::IsWritten(const StdString & filename) const |
---|
| 109 | { |
---|
| 110 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
| 111 | } |
---|
[887] | 112 | |
---|
[1940] | 113 | void CScalar::addRelFile(const StdString& filename) |
---|
| 114 | { |
---|
[887] | 115 | this->relFiles.insert(filename); |
---|
[1940] | 116 | } |
---|
[887] | 117 | |
---|
[1940] | 118 | void CScalar::checkAttributes(void) |
---|
| 119 | { |
---|
| 120 | if (checkAttributes_done_) return ; |
---|
| 121 | checkAttributes_done_ = true ; |
---|
[2264] | 122 | |
---|
| 123 | if (n.isEmpty()) n=1 ; |
---|
[1940] | 124 | if (mask.isEmpty()) mask=true ; |
---|
[887] | 125 | |
---|
[1940] | 126 | initializeLocalElement() ; |
---|
| 127 | addFullView() ; |
---|
| 128 | addWorkflowView() ; |
---|
| 129 | addModelView() ; |
---|
| 130 | } |
---|
| 131 | |
---|
[1158] | 132 | /*! |
---|
| 133 | Compare two scalar objects. |
---|
| 134 | They are equal if only if they have identical attributes as well as their values. |
---|
| 135 | Moreover, they must have the same transformations. |
---|
| 136 | \param [in] scalar Compared scalar |
---|
| 137 | \return result of the comparison |
---|
| 138 | */ |
---|
| 139 | bool CScalar::isEqual(CScalar* obj) |
---|
| 140 | { |
---|
| 141 | vector<StdString> excludedAttr; |
---|
| 142 | excludedAttr.push_back("scalar_ref"); |
---|
| 143 | bool objEqual = SuperClass::isEqual(obj, excludedAttr); |
---|
| 144 | if (!objEqual) return objEqual; |
---|
| 145 | |
---|
| 146 | TransMapTypes thisTrans = this->getAllTransformations(); |
---|
| 147 | TransMapTypes objTrans = obj->getAllTransformations(); |
---|
| 148 | |
---|
| 149 | TransMapTypes::const_iterator it, itb, ite; |
---|
| 150 | std::vector<ETranformationType> thisTransType, objTransType; |
---|
| 151 | for (it = thisTrans.begin(); it != thisTrans.end(); ++it) |
---|
| 152 | thisTransType.push_back(it->first); |
---|
| 153 | for (it = objTrans.begin(); it != objTrans.end(); ++it) |
---|
| 154 | objTransType.push_back(it->first); |
---|
| 155 | |
---|
| 156 | if (thisTransType.size() != objTransType.size()) return false; |
---|
| 157 | for (int idx = 0; idx < thisTransType.size(); ++idx) |
---|
| 158 | objEqual &= (thisTransType[idx] == objTransType[idx]); |
---|
| 159 | |
---|
| 160 | return objEqual; |
---|
| 161 | } |
---|
| 162 | |
---|
[887] | 163 | CTransformation<CScalar>* CScalar::addTransformation(ETranformationType transType, const StdString& id) |
---|
| 164 | { |
---|
| 165 | transformationMap_.push_back(std::make_pair(transType, CTransformation<CScalar>::createTransformation(transType,id))); |
---|
| 166 | return transformationMap_.back().second; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | bool CScalar::hasTransformation() |
---|
| 170 | { |
---|
| 171 | return (!transformationMap_.empty()); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | void CScalar::setTransformations(const TransMapTypes& scalarTrans) |
---|
| 175 | { |
---|
| 176 | transformationMap_ = scalarTrans; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | CScalar::TransMapTypes CScalar::getAllTransformations(void) |
---|
| 180 | { |
---|
| 181 | return transformationMap_; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void CScalar::duplicateTransformation(CScalar* src) |
---|
| 185 | { |
---|
| 186 | if (src->hasTransformation()) |
---|
| 187 | { |
---|
| 188 | this->setTransformations(src->getAllTransformations()); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /*! |
---|
| 193 | * Go through the hierarchy to find the scalar from which the transformations must be inherited |
---|
| 194 | */ |
---|
[1984] | 195 | void CScalar::solveInheritanceTransformation_old() |
---|
[887] | 196 | { |
---|
| 197 | if (hasTransformation() || !hasDirectScalarReference()) |
---|
| 198 | return; |
---|
| 199 | |
---|
| 200 | CScalar* scalar = this; |
---|
| 201 | std::vector<CScalar*> refScalar; |
---|
| 202 | while (!scalar->hasTransformation() && scalar->hasDirectScalarReference()) |
---|
| 203 | { |
---|
| 204 | refScalar.push_back(scalar); |
---|
| 205 | scalar = scalar->getDirectScalarReference(); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | if (scalar->hasTransformation()) |
---|
| 209 | for (size_t i = 0; i < refScalar.size(); ++i) |
---|
| 210 | refScalar[i]->setTransformations(scalar->getAllTransformations()); |
---|
| 211 | } |
---|
[1875] | 212 | |
---|
[1984] | 213 | void CScalar::solveInheritanceTransformation() |
---|
| 214 | TRY |
---|
| 215 | { |
---|
| 216 | if (solveInheritanceTransformation_done_) return; |
---|
| 217 | else solveInheritanceTransformation_done_=true ; |
---|
| 218 | |
---|
| 219 | CScalar* scalar = this; |
---|
| 220 | CScalar* Lastscalar ; |
---|
| 221 | std::list<CScalar*> refScalars; |
---|
| 222 | bool out=false ; |
---|
| 223 | vector<StdString> excludedAttr; |
---|
| 224 | excludedAttr.push_back("scalar_ref"); |
---|
| 225 | |
---|
| 226 | refScalars.push_front(scalar) ; |
---|
| 227 | while (scalar->hasDirectScalarReference() && !out) |
---|
| 228 | { |
---|
| 229 | CScalar* lastScalar=scalar ; |
---|
| 230 | scalar = scalar->getDirectScalarReference(); |
---|
| 231 | scalar->solveRefInheritance() ; |
---|
| 232 | if (!scalar->SuperClass::isEqual(lastScalar,excludedAttr)) out=true ; |
---|
| 233 | refScalars.push_front(scalar) ; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | CTransformationPaths::TPath path ; |
---|
| 237 | auto& pathList = std::get<2>(path) ; |
---|
| 238 | std::get<0>(path) = EElement::SCALAR ; |
---|
| 239 | std::get<1>(path) = refScalars.front()->getId() ; |
---|
| 240 | for (auto& scalar : refScalars) |
---|
| 241 | { |
---|
| 242 | CScalar::TransMapTypes transformations = scalar->getAllTransformations(); |
---|
| 243 | for(auto& transformation : transformations) pathList.push_back({transformation.second->getTransformationType(), |
---|
| 244 | transformation.second->getId()}) ; |
---|
| 245 | } |
---|
| 246 | transformationPaths_.addPath(path) ; |
---|
| 247 | |
---|
| 248 | } |
---|
| 249 | CATCH_DUMP_ATTR |
---|
| 250 | |
---|
[2206] | 251 | bool CScalar::activateFieldWorkflow(CGarbageCollector& gc) |
---|
| 252 | TRY |
---|
| 253 | { |
---|
| 254 | if (!scalar_ref.isEmpty()) |
---|
| 255 | { |
---|
| 256 | CField* field=getFieldFromId(scalar_ref) ; |
---|
| 257 | if (field!=nullptr) |
---|
| 258 | { |
---|
| 259 | bool ret = field->buildWorkflowGraph(gc) ; |
---|
| 260 | if (!ret) return false ; // cannot build workflow graph at this state |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | CScalar* scalar = get(scalar_ref) ; |
---|
| 265 | bool ret = scalar->activateFieldWorkflow(gc) ; |
---|
| 266 | if (!ret) return false ; // cannot build workflow graph at this state |
---|
| 267 | scalar_ref=scalar->getId() ; // replace domain_ref by solved reference |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | activateFieldWorkflow_done_=true ; |
---|
| 271 | return true ; |
---|
| 272 | } |
---|
| 273 | CATCH_DUMP_ATTR |
---|
| 274 | |
---|
| 275 | |
---|
[1975] | 276 | /* obsolete, to remove after reimplementing coupling */ |
---|
[1875] | 277 | void CScalar::sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) |
---|
| 278 | { |
---|
| 279 | if (sendScalarToCouplerOut_done_.count(client)!=0) return ; |
---|
| 280 | else sendScalarToCouplerOut_done_.insert(client) ; |
---|
| 281 | |
---|
[2022] | 282 | string scalarId = getCouplingAlias(fieldId, posInGrid) ; |
---|
[1875] | 283 | |
---|
| 284 | this->sendAllAttributesToServer(client, scalarId); |
---|
| 285 | } |
---|
| 286 | |
---|
[2022] | 287 | string CScalar::getCouplingAlias(const string& fieldId, int posInGrid) |
---|
| 288 | { |
---|
| 289 | return "_scalar["+std::to_string(posInGrid)+"]_of_"+fieldId ; |
---|
| 290 | } |
---|
| 291 | |
---|
[1875] | 292 | void CScalar::makeAliasForCoupling(const string& fieldId, int posInGrid) |
---|
| 293 | { |
---|
[2022] | 294 | const string scalarId = getCouplingAlias(fieldId, posInGrid) ; |
---|
[1875] | 295 | this->createAlias(scalarId) ; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | void CScalar::setContextClient(CContextClient* contextClient) |
---|
| 299 | TRY |
---|
| 300 | { |
---|
| 301 | if (clientsSet.find(contextClient)==clientsSet.end()) |
---|
| 302 | { |
---|
| 303 | clients.push_back(contextClient) ; |
---|
| 304 | clientsSet.insert(contextClient); |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | CATCH_DUMP_ATTR |
---|
[888] | 308 | /*! |
---|
| 309 | Parse children nodes of a scalar in xml file. |
---|
| 310 | \param node child node to process |
---|
| 311 | */ |
---|
| 312 | void CScalar::parse(xml::CXMLNode & node) |
---|
| 313 | { |
---|
| 314 | SuperClass::parse(node); |
---|
[887] | 315 | |
---|
[888] | 316 | if (node.goToChildElement()) |
---|
| 317 | { |
---|
| 318 | StdString nodeElementName; |
---|
| 319 | do |
---|
| 320 | { |
---|
| 321 | StdString nodeId(""); |
---|
| 322 | if (node.getAttributes().end() != node.getAttributes().find("id")) |
---|
| 323 | { nodeId = node.getAttributes()["id"]; } |
---|
| 324 | |
---|
| 325 | nodeElementName = node.getElementName(); |
---|
| 326 | std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it; |
---|
| 327 | it = transformationMapList_.find(nodeElementName); |
---|
| 328 | if (ite != it) |
---|
| 329 | { |
---|
| 330 | transformationMap_.push_back(std::make_pair(it->second, CTransformation<CScalar>::createTransformation(it->second, |
---|
| 331 | nodeId, |
---|
| 332 | &node))); |
---|
| 333 | } |
---|
[968] | 334 | else |
---|
| 335 | { |
---|
| 336 | ERROR("void CScalar::parse(xml::CXMLNode & node)", |
---|
| 337 | << "The transformation " << nodeElementName << " has not been supported yet."); |
---|
| 338 | } |
---|
[888] | 339 | } while (node.goToNextElement()) ; |
---|
| 340 | node.goToParentElement(); |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
[1930] | 344 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
| 345 | // this part is related to distribution, element definition, views and connectors // |
---|
| 346 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
| 347 | |
---|
| 348 | void CScalar::initializeLocalElement(void) |
---|
| 349 | { |
---|
| 350 | // after checkAttribute index of size n |
---|
| 351 | int rank = CContext::getCurrent()->getIntraCommRank() ; |
---|
| 352 | |
---|
[2264] | 353 | |
---|
| 354 | CArray<size_t,1> index(n) ; |
---|
| 355 | if (n==1) index(0)=0 ; |
---|
[2267] | 356 | localElement_ = make_shared<CLocalElement>(rank, 1, index) ; |
---|
[1930] | 357 | } |
---|
| 358 | |
---|
| 359 | void CScalar::addFullView(void) |
---|
| 360 | { |
---|
[2264] | 361 | CArray<int,1> index(n) ; |
---|
| 362 | if (n==1) index(0)=0 ; |
---|
[1930] | 363 | localElement_ -> addView(CElementView::FULL, index) ; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | void CScalar::addWorkflowView(void) |
---|
| 367 | { |
---|
[1940] | 368 | CArray<int,1> index ; |
---|
[2264] | 369 | if (mask && n==1) |
---|
[1940] | 370 | { |
---|
| 371 | index.resize(1) ; |
---|
| 372 | index(0)=0 ; |
---|
| 373 | } |
---|
| 374 | else index.resize(0) ; |
---|
| 375 | localElement_ -> addView(CElementView::WORKFLOW, index) ; |
---|
[1930] | 376 | } |
---|
| 377 | |
---|
| 378 | void CScalar::addModelView(void) |
---|
| 379 | { |
---|
| 380 | CArray<int,1> index(1) ; |
---|
| 381 | for(int i=0; i<1 ; i++) index(0)=0 ; |
---|
| 382 | localElement_->addView(CElementView::MODEL, index) ; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | void CScalar::computeModelToWorkflowConnector(void) |
---|
| 386 | { |
---|
[2267] | 387 | shared_ptr<CLocalView> srcView=getLocalView(CElementView::MODEL) ; |
---|
| 388 | shared_ptr<CLocalView> dstView=getLocalView(CElementView::WORKFLOW) ; |
---|
| 389 | modelToWorkflowConnector_ = make_shared<CLocalConnector>(srcView, dstView); |
---|
[1930] | 390 | modelToWorkflowConnector_->computeConnector() ; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | |
---|
[1940] | 394 | void CScalar::computeRemoteElement(CContextClient* client, EDistributionType type) |
---|
[1930] | 395 | { |
---|
| 396 | CContext* context = CContext::getCurrent(); |
---|
| 397 | map<int, CArray<size_t,1>> globalIndex ; |
---|
| 398 | size_t nglo=1 ; |
---|
| 399 | |
---|
[2264] | 400 | if (type==EDistributionType::ROOT) // Bands distribution to send to file server |
---|
| 401 | { |
---|
| 402 | for (auto& rankServer : client->getRanksServerLeader()) |
---|
| 403 | { |
---|
| 404 | auto& globalInd = globalIndex[rankServer] ; |
---|
| 405 | if (rankServer==0) |
---|
| 406 | { |
---|
| 407 | globalInd.resize(1) ; |
---|
| 408 | globalInd(0)=0 ; |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | else if (type==EDistributionType::NONE) // domain is not distributed ie all servers get the same local domain |
---|
| 413 | { |
---|
[2343] | 414 | int nbServer = client->getRemoteSize(); |
---|
[2264] | 415 | CArray<size_t,1> indGlo(nglo) ; |
---|
| 416 | for(size_t i=0;i<nglo;i++) indGlo(i) = i ; |
---|
| 417 | for (auto& rankServer : client->getRanksServerLeader()) globalIndex[rankServer].reference(indGlo.copy()) ; |
---|
| 418 | } |
---|
[2267] | 419 | remoteElement_[client] = make_shared<CDistributedElement>(nglo, globalIndex) ; |
---|
[1930] | 420 | remoteElement_[client]->addFullView() ; |
---|
| 421 | } |
---|
| 422 | |
---|
[2397] | 423 | void CScalar::distributeToServer(CContextClient* client, bool inOut, std::map<int, CArray<size_t,1>>& globalIndexOut, std::map<int, CArray<size_t,1>>& globalIndexIn, |
---|
[2267] | 424 | shared_ptr<CScattererConnector> &scattererConnector, const string& scalarId) |
---|
[1930] | 425 | { |
---|
[1940] | 426 | string serverScalarId = scalarId.empty() ? this->getId() : scalarId ; |
---|
[1930] | 427 | CContext* context = CContext::getCurrent(); |
---|
[1940] | 428 | |
---|
| 429 | this->sendAllAttributesToServer(client, serverScalarId) ; |
---|
| 430 | |
---|
[2304] | 431 | auto scatteredElement = make_shared<CDistributedElement>(1,globalIndexOut) ; |
---|
[2267] | 432 | scatteredElement->addFullView() ; |
---|
| 433 | scattererConnector = make_shared<CScattererConnector>(localElement_->getView(CElementView::FULL), scatteredElement->getView(CElementView::FULL), |
---|
| 434 | context->getIntraComm(), client->getRemoteSize()) ; |
---|
[1958] | 435 | scattererConnector->computeConnector() ; |
---|
[1940] | 436 | |
---|
| 437 | // phase 0 |
---|
| 438 | // send remote element to construct the full view on server, ie without hole |
---|
| 439 | CEventClient event0(getType(), EVENT_ID_SCALAR_DISTRIBUTION); |
---|
| 440 | CMessage message0 ; |
---|
| 441 | message0<<serverScalarId<<0 ; |
---|
| 442 | remoteElement_[client]->sendToServer(client,event0,message0) ; |
---|
| 443 | |
---|
| 444 | // phase 1 |
---|
| 445 | // send the full view of element to construct the connector which connect distributed data coming from client to the full local view |
---|
| 446 | CEventClient event1(getType(), EVENT_ID_SCALAR_DISTRIBUTION); |
---|
| 447 | CMessage message1 ; |
---|
| 448 | message1<<serverScalarId<<1<<localElement_->getView(CElementView::FULL)->getGlobalSize() ; |
---|
[1958] | 449 | scattererConnector->transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event1,message1) ; |
---|
[1934] | 450 | |
---|
[2267] | 451 | sendDistributedAttributes(client, scattererConnector, scalarId) ; |
---|
[1940] | 452 | |
---|
| 453 | // phase 2 send the mask : data index + mask2D |
---|
[2304] | 454 | { |
---|
| 455 | CArray<bool,1> maskIn(localElement_->getView(CElementView::WORKFLOW)->getSize()); |
---|
| 456 | CArray<bool,1> maskOut ; |
---|
| 457 | auto workflowToFull = make_shared<CLocalConnector>(localElement_->getView(CElementView::WORKFLOW), localElement_->getView(CElementView::FULL)) ; |
---|
| 458 | workflowToFull->computeConnector() ; |
---|
| 459 | maskIn=true ; |
---|
| 460 | workflowToFull->transfer(maskIn,maskOut,false) ; |
---|
[1934] | 461 | |
---|
[2304] | 462 | // prepare grid scatterer connector to send data from client to server |
---|
| 463 | map<int,CArray<size_t,1>> workflowGlobalIndex ; |
---|
| 464 | map<int,CArray<bool,1>> maskOut2 ; |
---|
| 465 | scattererConnector->transfer(maskOut, maskOut2) ; |
---|
| 466 | scatteredElement->addView(CElementView::WORKFLOW, maskOut2) ; |
---|
| 467 | scatteredElement->getView(CElementView::WORKFLOW)->getGlobalIndexView(workflowGlobalIndex) ; |
---|
| 468 | // create new workflow view for scattered element |
---|
| 469 | auto clientToServerElement = make_shared<CDistributedElement>(scatteredElement->getGlobalSize(), workflowGlobalIndex) ; |
---|
| 470 | clientToServerElement->addFullView() ; |
---|
| 471 | CEventClient event2(getType(), EVENT_ID_SCALAR_DISTRIBUTION); |
---|
| 472 | CMessage message2 ; |
---|
| 473 | message2<<serverScalarId<<2 ; |
---|
| 474 | clientToServerElement->sendToServer(client, event2, message2) ; |
---|
| 475 | clientToServerConnector_[client] = make_shared<CScattererConnector>(localElement_->getView(CElementView::WORKFLOW), clientToServerElement->getView(CElementView::FULL), |
---|
| 476 | context->getIntraComm(), client->getRemoteSize()) ; |
---|
| 477 | clientToServerConnector_[client]->computeConnector() ; |
---|
| 478 | } |
---|
[1940] | 479 | |
---|
[2304] | 480 | //////////// |
---|
| 481 | // phase 3 : compute connector to receive from server |
---|
| 482 | //////////// |
---|
[2397] | 483 | if (inOut) |
---|
[2304] | 484 | { |
---|
| 485 | auto scatteredElement = make_shared<CDistributedElement>(1, globalIndexIn) ; |
---|
| 486 | scatteredElement->addFullView() ; |
---|
| 487 | auto scattererConnector = make_shared<CScattererConnector>(localElement_->getView(CElementView::FULL), scatteredElement->getView(CElementView::FULL), |
---|
| 488 | context->getIntraComm(), client->getRemoteSize()) ; |
---|
| 489 | scattererConnector->computeConnector() ; |
---|
| 490 | |
---|
| 491 | CArray<bool,1> maskIn(localElement_->getView(CElementView::WORKFLOW)->getSize()); |
---|
| 492 | CArray<bool,1> maskOut ; |
---|
| 493 | auto workflowToFull = make_shared<CLocalConnector>(localElement_->getView(CElementView::WORKFLOW), localElement_->getView(CElementView::FULL)) ; |
---|
| 494 | workflowToFull->computeConnector() ; |
---|
| 495 | maskIn=true ; |
---|
| 496 | workflowToFull->transfer(maskIn,maskOut,false) ; |
---|
[1940] | 497 | |
---|
[2304] | 498 | map<int,CArray<size_t,1>> workflowGlobalIndex ; |
---|
| 499 | map<int,CArray<bool,1>> maskOut2 ; |
---|
| 500 | scattererConnector->transfer(maskOut, maskOut2, false) ; |
---|
| 501 | scatteredElement->addView(CElementView::WORKFLOW, maskOut2) ; |
---|
| 502 | scatteredElement->getView(CElementView::WORKFLOW)->getGlobalIndexView(workflowGlobalIndex) ; |
---|
| 503 | auto clientToServerElement = make_shared<CDistributedElement>(scatteredElement->getGlobalSize(), workflowGlobalIndex) ; |
---|
| 504 | clientToServerElement->addFullView() ; |
---|
| 505 | CEventClient event3(getType(), EVENT_ID_SCALAR_DISTRIBUTION); |
---|
| 506 | CMessage message3 ; |
---|
| 507 | message3<<serverScalarId<<3 ; |
---|
| 508 | clientToServerElement->sendToServer(client, event3, message3) ; |
---|
| 509 | |
---|
| 510 | clientFromServerConnector_[client] = make_shared<CGathererConnector>(clientToServerElement->getView(CElementView::FULL), localElement_->getView(CElementView::WORKFLOW)); |
---|
| 511 | clientFromServerConnector_[client]->computeConnector() ; |
---|
| 512 | } |
---|
[1930] | 513 | } |
---|
[1940] | 514 | |
---|
| 515 | void CScalar::recvScalarDistribution(CEventServer& event) |
---|
| 516 | TRY |
---|
| 517 | { |
---|
| 518 | string scalarId; |
---|
| 519 | int phasis ; |
---|
| 520 | for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> scalarId >> phasis ; |
---|
| 521 | get(scalarId)->receivedScalarDistribution(event, phasis); |
---|
| 522 | } |
---|
| 523 | CATCH |
---|
| 524 | |
---|
| 525 | void CScalar::receivedScalarDistribution(CEventServer& event, int phasis) |
---|
| 526 | TRY |
---|
| 527 | { |
---|
| 528 | CContext* context = CContext::getCurrent(); |
---|
| 529 | if (phasis==0) // receive the remote element to construct the full view |
---|
| 530 | { |
---|
[2267] | 531 | localElement_ = make_shared<CLocalElement>(context->getIntraCommRank(),event) ; |
---|
[1940] | 532 | localElement_->addFullView() ; |
---|
| 533 | // construct the local dimension and indexes |
---|
| 534 | auto& globalIndex=localElement_->getGlobalIndex() ; |
---|
[2264] | 535 | n=globalIndex.numElements() ; |
---|
[1940] | 536 | // no distribution for scalar => nk ==1 or maybe 0 ? |
---|
| 537 | } |
---|
| 538 | else if (phasis==1) // receive the sent view from client to construct the full distributed full view on server |
---|
| 539 | { |
---|
| 540 | CContext* context = CContext::getCurrent(); |
---|
[2267] | 541 | shared_ptr<CDistributedElement> elementFrom = make_shared<CDistributedElement>(event) ; |
---|
[1940] | 542 | elementFrom->addFullView() ; |
---|
[2267] | 543 | gathererConnector_ = make_shared<CGathererConnector>(elementFrom->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; |
---|
[1940] | 544 | gathererConnector_->computeConnector() ; |
---|
| 545 | } |
---|
| 546 | else if (phasis==2) |
---|
| 547 | { |
---|
[1958] | 548 | // delete gathererConnector_ ; |
---|
[2267] | 549 | elementFrom_ = make_shared<CDistributedElement>(event) ; |
---|
[1940] | 550 | elementFrom_->addFullView() ; |
---|
[2267] | 551 | // gathererConnector_ = make_shared<CGathererConnector>(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; |
---|
[1958] | 552 | // gathererConnector_ -> computeConnector() ; |
---|
[1940] | 553 | } |
---|
[2304] | 554 | else if (phasis==3) |
---|
| 555 | { |
---|
| 556 | elementTo_ = make_shared<CDistributedElement>(event) ; |
---|
| 557 | elementTo_->addFullView() ; |
---|
| 558 | } |
---|
[1940] | 559 | } |
---|
| 560 | CATCH |
---|
| 561 | |
---|
[1943] | 562 | void CScalar::setServerMask(CArray<bool,1>& serverMask, CContextClient* client) |
---|
| 563 | TRY |
---|
| 564 | { |
---|
| 565 | CContext* context = CContext::getCurrent(); |
---|
| 566 | localElement_->addView(CElementView::WORKFLOW, serverMask) ; |
---|
[2264] | 567 | if (serverMask.numElements()==1) mask = serverMask(0) ; |
---|
[1943] | 568 | |
---|
[2267] | 569 | serverFromClientConnector_ = make_shared<CGathererConnector>(elementFrom_->getView(CElementView::FULL), localElement_->getView(CElementView::WORKFLOW)) ; |
---|
[1943] | 570 | serverFromClientConnector_->computeConnector() ; |
---|
[2397] | 571 | elementFrom_.reset() ; |
---|
[1943] | 572 | |
---|
[2397] | 573 | if (elementTo_) |
---|
| 574 | { |
---|
| 575 | serverToClientConnector_ = make_shared<CScattererConnector>(localElement_->getView(CElementView::WORKFLOW), elementTo_->getView(CElementView::FULL), |
---|
[2267] | 576 | context->getIntraComm(), client->getRemoteSize()) ; |
---|
[2397] | 577 | serverToClientConnector_->computeConnector() ; |
---|
| 578 | elementTo_.reset() ; |
---|
| 579 | } |
---|
[1943] | 580 | } |
---|
| 581 | CATCH_DUMP_ATTR |
---|
| 582 | |
---|
[2267] | 583 | void CScalar::sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& scalarId) |
---|
[1940] | 584 | { |
---|
| 585 | string serverScalarId = scalarId.empty() ? this->getId() : scalarId ; |
---|
| 586 | CContext* context = CContext::getCurrent(); |
---|
| 587 | |
---|
| 588 | // nothing for now |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | void CScalar::recvDistributedAttributes(CEventServer& event) |
---|
| 592 | TRY |
---|
| 593 | { |
---|
| 594 | string scalarId; |
---|
| 595 | string type ; |
---|
| 596 | for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> scalarId >> type ; |
---|
| 597 | get(scalarId)->recvDistributedAttributes(event, type); |
---|
| 598 | } |
---|
| 599 | CATCH |
---|
| 600 | |
---|
| 601 | void CScalar::recvDistributedAttributes(CEventServer& event, const string& type) |
---|
| 602 | TRY |
---|
| 603 | { |
---|
| 604 | // nothing for now |
---|
| 605 | } |
---|
| 606 | CATCH |
---|
| 607 | |
---|
| 608 | bool CScalar::dispatchEvent(CEventServer& event) |
---|
| 609 | TRY |
---|
| 610 | { |
---|
| 611 | if (SuperClass::dispatchEvent(event)) return true; |
---|
| 612 | else |
---|
| 613 | { |
---|
| 614 | switch(event.type) |
---|
| 615 | { |
---|
| 616 | case EVENT_ID_SCALAR_DISTRIBUTION: |
---|
| 617 | recvScalarDistribution(event); |
---|
| 618 | return true; |
---|
| 619 | break; |
---|
| 620 | case EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE: |
---|
| 621 | recvDistributedAttributes(event); |
---|
| 622 | return true; |
---|
| 623 | break; |
---|
| 624 | default : |
---|
| 625 | ERROR("bool CScalar::dispatchEvent(CEventServer& event)", |
---|
| 626 | << "Unknown Event"); |
---|
| 627 | return false; |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | } |
---|
| 631 | CATCH |
---|
| 632 | |
---|
| 633 | |
---|
[887] | 634 | // Definition of some macros |
---|
| 635 | DEFINE_REF_FUNC(Scalar,scalar) |
---|
| 636 | |
---|
| 637 | } // namespace xios |
---|