MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / SyncStrings

Method SyncStrings

Src/Base/AMReX_Utility.cpp:695–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693
694
695void 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 }

Callers

nothing calls this directly

Calls 11

IOProcessorNumberFunction · 0.85
IOProcessorFunction · 0.85
ReduceIntMaxFunction · 0.85
CommunicatorFunction · 0.85
NProcsFunction · 0.70
BcastFunction · 0.70
GatherFunction · 0.70
sizeMethod · 0.45
dataPtrMethod · 0.45
push_backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected