| 693 | |
| 694 | |
| 695 | void amrex::SyncStrings(const Vector<std::string> &localStrings, |
| 696 | Vector<std::string> &syncedStrings, bool &alreadySynced) |
| 697 | { |
| 698 | #ifdef BL_USE_MPI |
| 699 | const int nProcs(ParallelDescriptor::NProcs()); |
| 700 | const int ioProcNumber(ParallelDescriptor::IOProcessorNumber()); |
| 701 | int nUnmatched(0); |
| 702 | |
| 703 | Vector<std::string> localStringsCopy = localStrings; |
| 704 | |
| 705 | // ---- broadcast ioproc strings |
| 706 | int pfStringsSize(0); |
| 707 | std::ostringstream pfStrings; |
| 708 | if(ParallelDescriptor::IOProcessor()) { |
| 709 | for(const auto & i : localStringsCopy) { |
| 710 | pfStrings << i << '\n'; |
| 711 | } |
| 712 | pfStringsSize = static_cast<int>(pfStrings.str().size()); |
| 713 | } |
| 714 | ParallelDescriptor::Bcast(&pfStringsSize, 1); |
| 715 | |
| 716 | Vector<char> pfCharArray(pfStringsSize + 1); |
| 717 | if(ParallelDescriptor::IOProcessor()) { |
| 718 | std::strncpy(pfCharArray.dataPtr(), pfStrings.str().c_str(), pfCharArray.size()); // null terminated |
| 719 | } |
| 720 | ParallelDescriptor::Bcast(pfCharArray.dataPtr(), pfCharArray.size()); |
| 721 | |
| 722 | // ---- extract the ioproc strings |
| 723 | Vector<std::string> ioprocStrings, sendStrings; |
| 724 | if( ! ParallelDescriptor::IOProcessor()) { |
| 725 | std::istringstream pfIn(pfCharArray.dataPtr()); |
| 726 | std::string pfName; |
| 727 | while( ! pfIn.eof()) { |
| 728 | std::getline(pfIn, pfName, '\n'); |
| 729 | if( ! pfIn.eof()) { |
| 730 | ioprocStrings.push_back(pfName); |
| 731 | } |
| 732 | } |
| 733 | // ---- now check if they match on non ioprocs |
| 734 | for(const auto & ioprocString : ioprocStrings) { |
| 735 | bool matched(false); |
| 736 | for(const auto & i : localStringsCopy) { |
| 737 | if(ioprocString == i) { |
| 738 | matched = true; |
| 739 | } |
| 740 | } |
| 741 | if( ! matched) { |
| 742 | ++nUnmatched; |
| 743 | localStringsCopy.push_back(ioprocString); // ---- add to local set |
| 744 | } |
| 745 | } |
| 746 | for(const auto & n : localStringsCopy) { |
| 747 | bool matched(false); |
| 748 | for(const auto & ioprocString : ioprocStrings) { |
| 749 | if(n == ioprocString) { |
| 750 | matched = true; |
| 751 | } |
| 752 | } |
nothing calls this directly
no test coverage detected