mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support external MPI initialize / finalize (#1266)
This commit is contained in:
committed by
Andrew Heather
parent
29f9a3db27
commit
d5c01f1aa4
@ -0,0 +1,106 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-parallel-external-init
|
||||
|
||||
Description
|
||||
Simulate starting MPI outside of OpenFOAM
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "Time.H"
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include "vector.H"
|
||||
#include "IOstreams.H"
|
||||
#include "Pstream.H"
|
||||
|
||||
#include <mpi.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
bool startMPI()
|
||||
{
|
||||
int nprocs = 0, rank = 0;
|
||||
|
||||
MPI_Init(nullptr, nullptr);
|
||||
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
|
||||
if (nprocs && rank == 0)
|
||||
{
|
||||
std::cout<< nl << "Using MPI with " << nprocs << " procs" << nl << nl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool stopMPI()
|
||||
{
|
||||
Info<< nl << "Stopping MPI" << nl << nl;
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string message()
|
||||
{
|
||||
return
|
||||
(
|
||||
"rank " + name(Pstream::myProcNo())
|
||||
+ " / " + name(Pstream::nProcs()) + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noCheckProcessorDirectories();
|
||||
|
||||
UPstream::debug = 1;
|
||||
|
||||
startMPI();
|
||||
|
||||
#include "setRootCase.H"
|
||||
|
||||
Pout<< message().c_str();
|
||||
|
||||
stopMPI();
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user