From ce5618468193f2052887f7e7f04b726d87804b39 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Thu, 4 Nov 2010 12:13:43 +0100 Subject: [PATCH] multi-threading support for MUR-ABC added --- FDTD/engine_ext_mur_abc.cpp | 52 +++++++++++++++++++++++++++++-------- FDTD/engine_ext_mur_abc.h | 14 +++++++--- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/FDTD/engine_ext_mur_abc.cpp b/FDTD/engine_ext_mur_abc.cpp index f9da405..c160ef4 100644 --- a/FDTD/engine_ext_mur_abc.cpp +++ b/FDTD/engine_ext_mur_abc.cpp @@ -20,6 +20,7 @@ #include "engine.h" #include "engine_sse.h" #include "tools/array_ops.h" +#include "tools/useful.h" Engine_Ext_Mur_ABC::Engine_Ext_Mur_ABC(Operator_Ext_Mur_ABC* op_ext) : Engine_Extension(op_ext) { @@ -54,6 +55,8 @@ Engine_Ext_Mur_ABC::Engine_Ext_Mur_ABC(Operator_Ext_Mur_ABC* op_ext) : Engine_Ex m_start_TS = maxDelay + m_Op_mur->m_Op->Exc->Length + 10; //give it some extra timesteps, for the excitation to travel at least one cell away cerr << "Engine_Ext_Mur_ABC::Engine_Ext_Mur_ABC: Warning: Excitation inside the Mur-ABC #" << m_ny << "-" << (int)(m_LineNr>0) << " found!!!! Mur-ABC will be switched on after excitation is done at " << m_start_TS << " timesteps!!! " << endl; } + + SetNumberOfThreads(1); } Engine_Ext_Mur_ABC::~Engine_Ext_Mur_ABC() @@ -64,10 +67,25 @@ Engine_Ext_Mur_ABC::~Engine_Ext_Mur_ABC() m_volt_nyPP = NULL; } -void Engine_Ext_Mur_ABC::DoPreVoltageUpdates() + +void Engine_Ext_Mur_ABC::SetNumberOfThreads(int nrThread) +{ + Engine_Extension::SetNumberOfThreads(nrThread); + + m_numX = AssignJobs2Threads(m_numLines[0],m_NrThreads,false); + m_start.resize(m_NrThreads,0); + m_start.at(0)=0; + for (size_t n=1;n=m_NrThreads) + return; unsigned int pos[] = {0,0,0}; unsigned int pos_shift[] = {0,0,0}; pos[m_ny] = m_LineNr; @@ -78,8 +96,9 @@ void Engine_Ext_Mur_ABC::DoPreVoltageUpdates() { case Engine::BASIC: { - for (pos[m_nyP]=0;pos[m_nyP]=m_NrThreads) + return; unsigned int pos[] = {0,0,0}; unsigned int pos_shift[] = {0,0,0}; pos[m_ny] = m_LineNr; @@ -134,8 +156,9 @@ void Engine_Ext_Mur_ABC::DoPostVoltageUpdates() { case Engine::BASIC: { - for (pos[m_nyP]=0;pos[m_nyP]=m_NrThreads) + return; if (m_Eng==NULL) return; unsigned int pos[] = {0,0,0}; pos[m_ny] = m_LineNr; @@ -190,8 +217,9 @@ void Engine_Ext_Mur_ABC::Apply2Voltages() { case Engine::BASIC: { - for (pos[m_nyP]=0;pos[m_nyP]Engine::SetVolt(m_nyP,pos, m_volt_nyP[pos[m_nyP]][pos[m_nyPP]]); @@ -204,8 +232,9 @@ void Engine_Ext_Mur_ABC::Apply2Voltages() case Engine::SSE: { Engine_sse* eng_sse = (Engine_sse*) m_Eng; - for (pos[m_nyP]=0;pos[m_nyP]Engine_sse::SetVolt(m_nyP,pos, m_volt_nyP[pos[m_nyP]][pos[m_nyPP]]); @@ -216,8 +245,9 @@ void Engine_Ext_Mur_ABC::Apply2Voltages() } default: - for (pos[m_nyP]=0;pos[m_nyP]SetVolt(m_nyP,pos, m_volt_nyP[pos[m_nyP]][pos[m_nyPP]]); diff --git a/FDTD/engine_ext_mur_abc.h b/FDTD/engine_ext_mur_abc.h index 930bc82..c358596 100644 --- a/FDTD/engine_ext_mur_abc.h +++ b/FDTD/engine_ext_mur_abc.h @@ -30,9 +30,14 @@ public: Engine_Ext_Mur_ABC(Operator_Ext_Mur_ABC* op_ext); virtual ~Engine_Ext_Mur_ABC(); - virtual void DoPreVoltageUpdates(); - virtual void DoPostVoltageUpdates(); - virtual void Apply2Voltages(); + virtual void SetNumberOfThreads(int nrThread); + + virtual void DoPreVoltageUpdates() {Engine_Ext_Mur_ABC::DoPreVoltageUpdates(0);} + virtual void DoPreVoltageUpdates(int threadID); + virtual void DoPostVoltageUpdates() {Engine_Ext_Mur_ABC::DoPostVoltageUpdates(0);} + virtual void DoPostVoltageUpdates(int threadID); + virtual void Apply2Voltages() {Engine_Ext_Mur_ABC::Apply2Voltages(0);} + virtual void Apply2Voltages(int threadID); protected: Operator_Ext_Mur_ABC* m_Op_mur; @@ -46,6 +51,9 @@ protected: int m_LineNr_Shift; unsigned int m_numLines[2]; + vector m_start; + vector m_numX; + FDTD_FLOAT** m_Mur_Coeff_nyP; FDTD_FLOAT** m_Mur_Coeff_nyPP; FDTD_FLOAT** m_volt_nyP; //n+1 direction