| 645 | |
| 646 | |
| 647 | bool amrex::StreamRetry::TryFileOutput() |
| 648 | { |
| 649 | bool bTryOutput(false); |
| 650 | |
| 651 | if(tries == 0) { |
| 652 | bTryOutput = true; |
| 653 | } else { |
| 654 | |
| 655 | int nWriteErrors(nStreamErrors); |
| 656 | ParallelDescriptor::ReduceIntSum(nWriteErrors); |
| 657 | |
| 658 | if(nWriteErrors == 0) { // wrote a good file |
| 659 | bTryOutput = false; |
| 660 | } else { // wrote a bad file, rename it |
| 661 | if(ParallelDescriptor::IOProcessor()) { |
| 662 | const std::string& badFileName = amrex::Concatenate(fileName + ".bad", |
| 663 | tries - 1, 2); |
| 664 | if (amrex::Verbose() > 1) { |
| 665 | amrex::Print() << nWriteErrors << " STREAMERRORS : Renaming file from " |
| 666 | << fileName << " to " << badFileName << '\n'; |
| 667 | } |
| 668 | if (amrex::FileExists(badFileName)) { |
| 669 | FileSystem::RemoveAll(badFileName); |
| 670 | } |
| 671 | if (std::rename(fileName.c_str(), badFileName.c_str())) { |
| 672 | amrex::Abort("StreamRetry::TryFileOutput: std::rename failed"); |
| 673 | } |
| 674 | } |
| 675 | ParallelDescriptor::Barrier("StreamRetry::TryFileOutput"); // wait for file rename |
| 676 | |
| 677 | // check for maxtries and abort pref |
| 678 | if(tries < maxTries) { |
| 679 | bTryOutput = true; |
| 680 | } else { |
| 681 | if(abortOnRetryFailure) { |
| 682 | amrex::Abort("STREAMERROR : StreamRetry::maxTries exceeded."); |
| 683 | } |
| 684 | bTryOutput = false; |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | ++tries; |
| 690 | nStreamErrors = 0; |
| 691 | return bTryOutput; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void amrex::SyncStrings(const Vector<std::string> &localStrings, |
no test coverage detected