2011-02-08 13:08:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Thorsten Liebig (Thorsten.Liebig@gmx.de)
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "operator_mpi.h"
|
|
|
|
#include "operator_sse_compressed.h"
|
|
|
|
#include "engine_sse_compressed.h"
|
|
|
|
#include "engine_mpi.h"
|
2012-09-17 14:56:14 +00:00
|
|
|
#include "extensions/operator_extension.h"
|
2011-02-08 13:08:58 +00:00
|
|
|
#include "tools/array_ops.h"
|
2011-02-09 11:55:07 +00:00
|
|
|
#include "tools/useful.h"
|
|
|
|
#include "mpi.h"
|
2011-02-08 13:08:58 +00:00
|
|
|
|
|
|
|
Operator_MPI* Operator_MPI::New()
|
|
|
|
{
|
|
|
|
cout << "Create FDTD operator (compressed SSE + MPI)" << endl;
|
|
|
|
Operator_MPI* op = new Operator_MPI();
|
|
|
|
op->Init();
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
Operator_MPI::Operator_MPI() : Operator_SSE_Compressed()
|
|
|
|
{
|
2011-02-11 13:42:14 +00:00
|
|
|
m_NumProc = MPI::COMM_WORLD.Get_size();
|
|
|
|
|
|
|
|
//enabled only if more than one process is active
|
2011-03-08 10:29:48 +00:00
|
|
|
m_MPI_Enabled = m_NumProc>1;
|
2011-02-08 13:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Operator_MPI::~Operator_MPI()
|
|
|
|
{
|
|
|
|
Delete();
|
|
|
|
}
|
|
|
|
|
2011-02-11 13:42:14 +00:00
|
|
|
double Operator_MPI::CalcTimestep()
|
|
|
|
{
|
|
|
|
double ret = Operator::CalcTimestep();
|
|
|
|
|
|
|
|
if (!m_MPI_Enabled)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
double local_dT = dT;
|
2022-03-11 21:17:27 +00:00
|
|
|
//find the smallest time-step requests by all processings
|
2011-02-11 13:42:14 +00:00
|
|
|
MPI_Reduce(&local_dT, &dT, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
|
|
|
|
//send the smallest time-step to all
|
|
|
|
MPI_Bcast(&dT, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:55:07 +00:00
|
|
|
void Operator_MPI::SetBoundaryCondition(int* BCs)
|
|
|
|
{
|
2011-02-11 13:42:14 +00:00
|
|
|
if (!m_MPI_Enabled)
|
|
|
|
return Operator_SSE_Compressed::SetBoundaryCondition(BCs);
|
|
|
|
|
2011-02-09 11:55:07 +00:00
|
|
|
//set boundary conditions on MPI interfaces to PEC, ApplyElectricBC will handle proper interface handling...
|
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
|
|
|
if (m_NeighborUp[n]>=0)
|
|
|
|
BCs[2*n+1] = 0;
|
|
|
|
if (m_NeighborDown[n]>=0)
|
|
|
|
BCs[2*n] = 0;
|
|
|
|
}
|
|
|
|
Operator_SSE_Compressed::SetBoundaryCondition(BCs);
|
|
|
|
}
|
|
|
|
|
2014-01-06 14:40:39 +00:00
|
|
|
Engine* Operator_MPI::CreateEngine()
|
2011-02-08 13:08:58 +00:00
|
|
|
{
|
2011-02-11 13:42:14 +00:00
|
|
|
if (m_MPI_Enabled)
|
2014-01-06 14:40:39 +00:00
|
|
|
m_Engine = Engine_MPI::New(this);
|
2011-02-09 11:55:07 +00:00
|
|
|
else
|
2014-01-06 14:40:39 +00:00
|
|
|
m_Engine = Engine_SSE_Compressed::New(this);
|
|
|
|
return m_Engine;
|
2011-02-08 13:08:58 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 11:11:08 +00:00
|
|
|
void Operator_MPI::SetNeighborUp(int ny, int id)
|
|
|
|
{
|
|
|
|
if ((ny<0) || (ny>2))
|
|
|
|
return;
|
|
|
|
m_NeighborUp[ny]=id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator_MPI::SetNeighborDown(int ny, int id)
|
|
|
|
{
|
|
|
|
if ((ny<0) || (ny>2))
|
|
|
|
return;
|
|
|
|
m_NeighborDown[ny]=id;
|
|
|
|
}
|
|
|
|
|
2011-02-08 13:08:58 +00:00
|
|
|
void Operator_MPI::Init()
|
|
|
|
{
|
2011-02-09 11:55:07 +00:00
|
|
|
Operator_SSE_Compressed::Init();
|
|
|
|
|
|
|
|
m_MyTag = 0;
|
|
|
|
|
|
|
|
for (int i=0;i<3;++i)
|
|
|
|
{
|
|
|
|
m_NeighborUp[i]=-1;
|
|
|
|
m_NeighborDown[i]=-1;
|
2011-03-14 15:20:33 +00:00
|
|
|
m_OrigDiscLines[i]=NULL;
|
2011-02-09 11:55:07 +00:00
|
|
|
}
|
|
|
|
|
2011-03-28 08:26:08 +00:00
|
|
|
m_ProcTable = NULL;
|
|
|
|
m_SplitNumber[0]=0;
|
|
|
|
m_SplitNumber[1]=0;
|
|
|
|
m_SplitNumber[2]=0;
|
|
|
|
|
2011-02-09 11:55:07 +00:00
|
|
|
int namelen;
|
|
|
|
m_NumProc = MPI::COMM_WORLD.Get_size();
|
|
|
|
m_MyID = MPI::COMM_WORLD.Get_rank();
|
|
|
|
|
|
|
|
m_Processor_Name = new char[MPI_MAX_PROCESSOR_NAME];
|
|
|
|
MPI::Get_processor_name(m_Processor_Name,namelen);
|
|
|
|
|
2011-11-08 10:49:14 +00:00
|
|
|
if ((m_MPI_Enabled) && (g_settings.GetVerboseLevel()>0))
|
2011-02-11 13:42:14 +00:00
|
|
|
cerr << "Operator_MPI::Init(): Running on " << m_Processor_Name << endl;
|
2011-02-08 13:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Operator_MPI::Delete()
|
|
|
|
{
|
2011-02-09 11:55:07 +00:00
|
|
|
delete[] m_Processor_Name;
|
2011-03-14 15:20:33 +00:00
|
|
|
m_Processor_Name = NULL;
|
|
|
|
for (int i=0;i<3;++i)
|
|
|
|
{
|
|
|
|
delete[] m_OrigDiscLines[i];
|
|
|
|
m_OrigDiscLines[i] = NULL;
|
|
|
|
}
|
2011-03-28 08:26:08 +00:00
|
|
|
Delete3DArray(m_ProcTable,m_SplitNumber);
|
|
|
|
m_ProcTable=NULL;
|
2011-02-08 13:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Operator_MPI::Reset()
|
|
|
|
{
|
|
|
|
Delete();
|
2011-02-09 11:55:07 +00:00
|
|
|
Operator_SSE_Compressed::Reset();
|
2011-02-08 13:08:58 +00:00
|
|
|
}
|
2011-02-21 09:00:11 +00:00
|
|
|
|
2011-03-14 15:20:33 +00:00
|
|
|
void Operator_MPI::SetOriginalMesh(CSRectGrid* orig_Mesh)
|
|
|
|
{
|
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
|
|
|
delete[] m_OrigDiscLines[n];
|
2011-03-28 08:26:08 +00:00
|
|
|
m_OrigDiscLines[n] = orig_Mesh->GetLines(n,NULL,m_OrigNumLines[n]);
|
2011-03-14 15:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-06 15:33:12 +00:00
|
|
|
unsigned int Operator_MPI::GetNumberOfLines(int ny, bool fullMesh) const
|
2011-03-15 08:41:29 +00:00
|
|
|
{
|
2013-02-06 15:33:12 +00:00
|
|
|
if (fullMesh)
|
|
|
|
return Operator_SSE_Compressed::GetNumberOfLines(ny,fullMesh);
|
|
|
|
|
2011-03-15 08:41:29 +00:00
|
|
|
if ((!m_MPI_Enabled) || (m_NeighborUp[ny]<0))
|
2013-02-06 15:33:12 +00:00
|
|
|
return Operator_SSE_Compressed::GetNumberOfLines(ny,fullMesh);
|
2011-03-15 08:41:29 +00:00
|
|
|
|
|
|
|
return Operator_SSE_Compressed::GetNumberOfLines(ny)-1;
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:56:14 +00:00
|
|
|
void Operator_MPI::AddExtension(Operator_Extension* op_ext)
|
|
|
|
{
|
|
|
|
if (m_MPI_Enabled==false)
|
|
|
|
return Operator_SSE_Compressed::AddExtension(op_ext);
|
|
|
|
|
|
|
|
if (op_ext->IsMPISave())
|
|
|
|
Operator_SSE_Compressed::AddExtension(op_ext);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "Operator_MPI::AddExtension: Warning: Operator extension \"" << op_ext->GetExtensionName() << "\" is not compatible with MPI!! skipping...!" << endl;
|
2012-10-29 13:51:02 +00:00
|
|
|
delete op_ext;
|
2012-09-17 14:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 09:00:11 +00:00
|
|
|
string Operator_MPI::PrependRank(string name)
|
|
|
|
{
|
|
|
|
stringstream out_name;
|
|
|
|
if (m_MPI_Enabled)
|
|
|
|
out_name << "ID" << m_MyID << "_" << name;
|
|
|
|
else
|
|
|
|
out_name << name;
|
|
|
|
return out_name.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator_MPI::DumpOperator2File(string filename)
|
|
|
|
{
|
|
|
|
Operator_SSE_Compressed::DumpOperator2File(PrependRank(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator_MPI::DumpMaterial2File(string filename)
|
|
|
|
{
|
|
|
|
Operator_SSE_Compressed::DumpMaterial2File(PrependRank(filename));
|
|
|
|
}
|
|
|
|
|
2013-03-27 11:02:08 +00:00
|
|
|
void Operator_MPI::DumpPEC2File(string filename , unsigned int *range)
|
2011-02-21 09:00:11 +00:00
|
|
|
{
|
2013-03-27 11:02:08 +00:00
|
|
|
Operator_SSE_Compressed::DumpPEC2File(PrependRank(filename), range);
|
2011-02-21 09:00:11 +00:00
|
|
|
}
|