engine independent multi-threading
parent
54d0671d33
commit
7f70f0fb4d
|
@ -33,11 +33,30 @@ Engine::Engine(const Operator* op)
|
|||
{
|
||||
Op = op;
|
||||
for (int n=0;n<3;++n)
|
||||
{
|
||||
// numLines[n] = Op->GetNumberOfLines(n);
|
||||
numLines[n] = Op->numLines[n];
|
||||
}
|
||||
numLines[n] = Op->GetOriginalNumLines(n);
|
||||
volt=NULL;
|
||||
curr=NULL;
|
||||
}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void Engine::Init()
|
||||
{
|
||||
Reset();
|
||||
numTS = 0;
|
||||
volt = Create_N_3DArray(numLines);
|
||||
curr = Create_N_3DArray(numLines);
|
||||
|
||||
file_et1.open( "et1" );
|
||||
|
||||
InitExtensions();
|
||||
}
|
||||
|
||||
void Engine::InitExtensions()
|
||||
{
|
||||
for (size_t n=0;n<Op->GetNumberOfExtentions();++n)
|
||||
{
|
||||
Operator_Extension* op_ext = Op->GetExtension(n);
|
||||
|
@ -50,24 +69,6 @@ Engine::Engine(const Operator* op)
|
|||
}
|
||||
}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
delete m_Eng_exts.at(n);
|
||||
m_Eng_exts.clear();
|
||||
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void Engine::Init()
|
||||
{
|
||||
numTS = 0;
|
||||
volt = Create_N_3DArray(numLines);
|
||||
curr = Create_N_3DArray(numLines);
|
||||
|
||||
file_et1.open( "et1" );
|
||||
}
|
||||
|
||||
void Engine::Reset()
|
||||
{
|
||||
Delete_N_3DArray(volt,numLines);
|
||||
|
@ -76,15 +77,20 @@ void Engine::Reset()
|
|||
curr=NULL;
|
||||
|
||||
file_et1.close();
|
||||
|
||||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
delete m_Eng_exts.at(n);
|
||||
m_Eng_exts.clear();
|
||||
}
|
||||
|
||||
void Engine::UpdateVoltages()
|
||||
void Engine::UpdateVoltages(unsigned int startX, unsigned int numX)
|
||||
{
|
||||
unsigned int pos[3];
|
||||
bool shift[3];
|
||||
|
||||
pos[0] = startX;
|
||||
//voltage updates
|
||||
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
|
||||
for (unsigned int posX=0;posX<numX;++posX)
|
||||
{
|
||||
shift[0]=pos[0];
|
||||
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
|
||||
|
@ -107,6 +113,7 @@ void Engine::UpdateVoltages()
|
|||
volt[2][pos[0]][pos[1]][pos[2]] += Op->vi[2][pos[0]][pos[1]][pos[2]] * ( curr[1][pos[0]][pos[1]][pos[2]] - curr[1][pos[0]-shift[0]][pos[1]][pos[2]] - curr[0][pos[0]][pos[1]][pos[2]] + curr[0][pos[0]][pos[1]-shift[1]][pos[2]]);
|
||||
}
|
||||
}
|
||||
++pos[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,10 +137,11 @@ void Engine::ApplyVoltageExcite()
|
|||
}
|
||||
}
|
||||
|
||||
void Engine::UpdateCurrents()
|
||||
void Engine::UpdateCurrents(unsigned int startX, unsigned int numX)
|
||||
{
|
||||
unsigned int pos[3];
|
||||
for (pos[0]=0;pos[0]<numLines[0]-1;++pos[0])
|
||||
pos[0] = startX;
|
||||
for (unsigned int posX=0;posX<numX;++posX)
|
||||
{
|
||||
for (pos[1]=0;pos[1]<numLines[1]-1;++pos[1])
|
||||
{
|
||||
|
@ -153,6 +161,7 @@ void Engine::UpdateCurrents()
|
|||
curr[2][pos[0]][pos[1]][pos[2]] += Op->iv[2][pos[0]][pos[1]][pos[2]] * ( volt[1][pos[0]][pos[1]][pos[2]] - volt[1][pos[0]+1][pos[1]][pos[2]] - volt[0][pos[0]][pos[1]][pos[2]] + volt[0][pos[0]][pos[1]+1][pos[2]]);
|
||||
}
|
||||
}
|
||||
++pos[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +186,7 @@ bool Engine::IterateTS(unsigned int iterTS)
|
|||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
m_Eng_exts.at(n)->DoPreVoltageUpdates();
|
||||
|
||||
UpdateVoltages();
|
||||
UpdateVoltages(0,numLines[0]);
|
||||
|
||||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
m_Eng_exts.at(n)->DoPostVoltageUpdates();
|
||||
|
@ -190,7 +199,7 @@ bool Engine::IterateTS(unsigned int iterTS)
|
|||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
m_Eng_exts.at(n)->DoPreCurrentUpdates();
|
||||
|
||||
UpdateCurrents();
|
||||
UpdateCurrents(0,numLines[0]-1);
|
||||
|
||||
for (size_t n=0;n<m_Eng_exts.size();++n)
|
||||
m_Eng_exts.at(n)->DoPostCurrentUpdates();
|
||||
|
|
|
@ -43,21 +43,25 @@ public:
|
|||
inline virtual FDTD_FLOAT& GetVolt( unsigned int n, unsigned int pos[] ) { return GetVolt(n,pos[0],pos[1],pos[2]); }
|
||||
inline virtual FDTD_FLOAT& GetCurr( unsigned int n, unsigned int pos[] ) { return GetCurr(n,pos[0],pos[1],pos[2]); }
|
||||
|
||||
virtual void UpdateVoltages(unsigned int startX, unsigned int numX);
|
||||
virtual void ApplyVoltageExcite();
|
||||
virtual void UpdateCurrents(unsigned int startX, unsigned int numX);
|
||||
virtual void ApplyCurrentExcite();
|
||||
|
||||
inline size_t GetExtensionCount() {return m_Eng_exts.size();}
|
||||
inline Engine_Extension* GetExtension(size_t nr) {return m_Eng_exts.at(nr);}
|
||||
|
||||
protected:
|
||||
Engine(const Operator* op);
|
||||
const Operator* Op;
|
||||
|
||||
virtual void UpdateVoltages();
|
||||
virtual void ApplyVoltageExcite();
|
||||
virtual void UpdateCurrents();
|
||||
virtual void ApplyCurrentExcite();
|
||||
|
||||
unsigned int numLines[3];
|
||||
|
||||
FDTD_FLOAT**** volt;
|
||||
FDTD_FLOAT**** curr;
|
||||
unsigned int numTS;
|
||||
|
||||
virtual void InitExtensions();
|
||||
vector<Engine_Extension*> m_Eng_exts;
|
||||
|
||||
ofstream file_et1;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include "engine_multithread.h"
|
||||
#include "engine_extension.h"
|
||||
#include "tools/array_ops.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
@ -44,6 +45,7 @@ Engine_Multithread* Engine_Multithread::New(const Operator* op, unsigned int num
|
|||
|
||||
Engine_Multithread::Engine_Multithread(const Operator* op) : Engine(op)
|
||||
{
|
||||
m_RunEngine = NULL;
|
||||
}
|
||||
|
||||
Engine_Multithread::~Engine_Multithread()
|
||||
|
@ -74,16 +76,24 @@ void Engine_Multithread::setNumThreads( unsigned int numThreads )
|
|||
|
||||
void Engine_Multithread::Init()
|
||||
{
|
||||
Engine::Init(); // gets cleaned up by Engine::~Engine()
|
||||
delete m_RunEngine;
|
||||
m_RunEngine = Op->CreateEngine();
|
||||
|
||||
// initialize threads
|
||||
m_stopThreads = false;
|
||||
if (m_numThreads == 0)
|
||||
m_numThreads = boost::thread::hardware_concurrency();
|
||||
cout << "using " << m_numThreads << " threads" << std::endl;
|
||||
m_barrier1 = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
m_barrier2 = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
m_barrier3 = new boost::barrier(m_numThreads); // numThread workers
|
||||
m_barrier_VoltUpdate = new boost::barrier(m_numThreads); // numThread workers
|
||||
m_barrier_VoltExcite = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
m_barrier_CurrUpdate = new boost::barrier(m_numThreads); // numThread workers
|
||||
m_barrier_CurrExcite = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
|
||||
m_barrier_PreVolt = new boost::barrier(m_numThreads); // numThread workers
|
||||
m_barrier_PostVolt = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
m_barrier_PreCurr = new boost::barrier(m_numThreads); // numThread workers
|
||||
m_barrier_PostCurr = new boost::barrier(m_numThreads+1); // numThread workers + 1 excitation thread
|
||||
|
||||
m_startBarrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
|
||||
m_stopBarrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
|
||||
|
||||
|
@ -117,14 +127,20 @@ void Engine_Multithread::Reset()
|
|||
m_stopThreads = true;
|
||||
m_stopBarrier->wait(); // wait for the threads to finish
|
||||
m_thread_group.join_all(); // wait for termination
|
||||
delete m_barrier1; m_barrier1 = 0;
|
||||
delete m_barrier2; m_barrier2 = 0;
|
||||
delete m_barrier3; m_barrier3 = 0;
|
||||
delete m_barrier_VoltUpdate; m_barrier_VoltUpdate = 0;
|
||||
delete m_barrier_VoltExcite; m_barrier_VoltExcite = 0;
|
||||
delete m_barrier_PreVolt; m_barrier_PreVolt = 0;
|
||||
delete m_barrier_PostVolt; m_barrier_PostVolt = 0;
|
||||
delete m_barrier_CurrUpdate; m_barrier_CurrUpdate = 0;
|
||||
delete m_barrier_CurrExcite; m_barrier_CurrExcite = 0;
|
||||
delete m_barrier_PreCurr; m_barrier_PreCurr = 0;
|
||||
delete m_barrier_PostCurr; m_barrier_PostCurr = 0;
|
||||
delete m_startBarrier; m_startBarrier = 0;
|
||||
delete m_stopBarrier; m_stopBarrier = 0;
|
||||
}
|
||||
|
||||
Engine::Reset();
|
||||
delete m_RunEngine;
|
||||
m_RunEngine = NULL;
|
||||
}
|
||||
|
||||
bool Engine_Multithread::IterateTS(unsigned int iterTS)
|
||||
|
@ -159,8 +175,6 @@ void thread::operator()()
|
|||
//std::cout << "thread::operator() Parameters: " << m_start << " " << m_stop << std::endl;
|
||||
//DBG().cout() << "Thread " << m_threadID << " (" << boost::this_thread::get_id() << ") started." << endl;
|
||||
|
||||
unsigned int pos[3];
|
||||
bool shift[3];
|
||||
|
||||
while (!m_enginePtr->m_stopThreads) {
|
||||
// wait for start
|
||||
|
@ -172,81 +186,59 @@ void thread::operator()()
|
|||
|
||||
for (unsigned int iter=0;iter<m_enginePtr->m_iterTS;++iter)
|
||||
{
|
||||
// pre voltage stuff...
|
||||
for (size_t n=m_threadID;n<m_enginePtr->m_RunEngine->GetExtensionCount();n+=m_enginePtr->m_numThreads)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->DoPreVoltageUpdates();
|
||||
|
||||
m_enginePtr->m_barrier_PreVolt->wait();
|
||||
|
||||
//voltage updates
|
||||
for (pos[0]=m_start;pos[0]<=m_stop;++pos[0])
|
||||
{
|
||||
shift[0]=pos[0];
|
||||
for (pos[1]=0;pos[1]<m_enginePtr->numLines[1];++pos[1])
|
||||
{
|
||||
shift[1]=pos[1];
|
||||
for (pos[2]=0;pos[2]<m_enginePtr->numLines[2];++pos[2])
|
||||
{
|
||||
shift[2]=pos[2];
|
||||
//do the updates here
|
||||
//for x
|
||||
m_enginePtr->volt[0][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->vv[0][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->volt[0][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->vi[0][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->curr[2][pos[0]][pos[1]][pos[2]] - m_enginePtr->curr[2][pos[0]][pos[1]-shift[1]][pos[2]] - m_enginePtr->curr[1][pos[0]][pos[1]][pos[2]] + m_enginePtr->curr[1][pos[0]][pos[1]][pos[2]-shift[2]]);
|
||||
|
||||
//for y
|
||||
m_enginePtr->volt[1][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->vv[1][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->volt[1][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->vi[1][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->curr[0][pos[0]][pos[1]][pos[2]] - m_enginePtr->curr[0][pos[0]][pos[1]][pos[2]-shift[2]] - m_enginePtr->curr[2][pos[0]][pos[1]][pos[2]] + m_enginePtr->curr[2][pos[0]-shift[0]][pos[1]][pos[2]]);
|
||||
|
||||
//for x
|
||||
m_enginePtr->volt[2][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->vv[2][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->volt[2][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->vi[2][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->curr[1][pos[0]][pos[1]][pos[2]] - m_enginePtr->curr[1][pos[0]-shift[0]][pos[1]][pos[2]] - m_enginePtr->curr[0][pos[0]][pos[1]][pos[2]] + m_enginePtr->curr[0][pos[0]][pos[1]-shift[1]][pos[2]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_enginePtr->m_RunEngine->UpdateVoltages(m_start,m_stop-m_start+1);
|
||||
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
|
||||
//cout << "Thread " << boost::this_thread::get_id() << " m_barrier1 waiting..." << endl;
|
||||
m_enginePtr->m_barrier1->wait();
|
||||
m_enginePtr->m_barrier_VoltUpdate->wait();
|
||||
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
|
||||
// e-field excitation (thread thread_e_excitation)
|
||||
//post voltage stuff...
|
||||
for (size_t n=m_threadID;n<m_enginePtr->m_RunEngine->GetExtensionCount();n+=m_enginePtr->m_numThreads)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->DoPostVoltageUpdates();
|
||||
m_enginePtr->m_barrier_PostVolt->wait();
|
||||
|
||||
m_enginePtr->m_barrier2->wait();
|
||||
// e-field excitation (thread thread_e_excitation)
|
||||
m_enginePtr->m_barrier_VoltExcite->wait();
|
||||
// e_excitation finished
|
||||
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
|
||||
//pre current stuff
|
||||
for (size_t n=m_threadID;n<m_enginePtr->m_RunEngine->GetExtensionCount();n+=m_enginePtr->m_numThreads)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->DoPreCurrentUpdates();
|
||||
m_enginePtr->m_barrier_PreCurr->wait();
|
||||
|
||||
//current updates
|
||||
for (pos[0]=m_start;pos[0]<=m_stop_h;++pos[0])
|
||||
{
|
||||
for (pos[1]=0;pos[1]<m_enginePtr->numLines[1]-1;++pos[1])
|
||||
{
|
||||
for (pos[2]=0;pos[2]<m_enginePtr->numLines[2]-1;++pos[2])
|
||||
{
|
||||
//do the updates here
|
||||
//for x
|
||||
m_enginePtr->curr[0][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->ii[0][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->curr[0][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->iv[0][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->volt[2][pos[0]][pos[1]][pos[2]] - m_enginePtr->volt[2][pos[0]][pos[1]+1][pos[2]] - m_enginePtr->volt[1][pos[0]][pos[1]][pos[2]] + m_enginePtr->volt[1][pos[0]][pos[1]][pos[2]+1]);
|
||||
m_enginePtr->m_RunEngine->UpdateCurrents(m_start,m_stop_h-m_start+1);
|
||||
|
||||
//for y
|
||||
m_enginePtr->curr[1][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->ii[1][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->curr[1][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->iv[1][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->volt[0][pos[0]][pos[1]][pos[2]] - m_enginePtr->volt[0][pos[0]][pos[1]][pos[2]+1] - m_enginePtr->volt[2][pos[0]][pos[1]][pos[2]] + m_enginePtr->volt[2][pos[0]+1][pos[1]][pos[2]]);
|
||||
|
||||
//for x
|
||||
m_enginePtr->curr[2][pos[0]][pos[1]][pos[2]] *= m_enginePtr->Op->ii[2][pos[0]][pos[1]][pos[2]];
|
||||
m_enginePtr->curr[2][pos[0]][pos[1]][pos[2]] += m_enginePtr->Op->iv[2][pos[0]][pos[1]][pos[2]] * ( m_enginePtr->volt[1][pos[0]][pos[1]][pos[2]] - m_enginePtr->volt[1][pos[0]+1][pos[1]][pos[2]] - m_enginePtr->volt[0][pos[0]][pos[1]][pos[2]] + m_enginePtr->volt[0][pos[0]][pos[1]+1][pos[2]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
m_enginePtr->m_barrier_CurrUpdate->wait();
|
||||
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
|
||||
m_enginePtr->m_barrier3->wait();
|
||||
|
||||
// record time
|
||||
DEBUG_TIME( m_enginePtr->m_timer_list[boost::this_thread::get_id()].push_back( timer1.elapsed() ); )
|
||||
//post current stuff
|
||||
for (size_t n=m_threadID;n<m_enginePtr->m_RunEngine->GetExtensionCount();n+=m_enginePtr->m_numThreads)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->DoPostCurrentUpdates();
|
||||
m_enginePtr->m_barrier_PostCurr->wait();
|
||||
|
||||
//soft current excitation here (H-field excite)
|
||||
m_enginePtr->m_barrier_CurrExcite->wait();
|
||||
// excitation finished
|
||||
|
||||
if (m_threadID == 0)
|
||||
++m_enginePtr->numTS; // only the first thread increments numTS
|
||||
|
@ -277,11 +269,24 @@ void thread_e_excitation::operator()()
|
|||
|
||||
while (!m_enginePtr->m_stopThreads)
|
||||
{
|
||||
m_enginePtr->m_barrier1->wait(); // waiting on NS_Engine_Multithread::thread
|
||||
m_enginePtr->m_barrier_PostVolt->wait(); // waiting on NS_Engine_Multithread::thread
|
||||
|
||||
for (size_t n=0;n<m_enginePtr->m_RunEngine->GetExtensionCount();++n)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->Apply2Voltages();
|
||||
|
||||
m_enginePtr->ApplyVoltageExcite();
|
||||
|
||||
m_enginePtr->m_barrier2->wait(); // continue NS_Engine_Multithread::thread
|
||||
m_enginePtr->m_barrier_VoltExcite->wait(); // continue NS_Engine_Multithread::thread
|
||||
|
||||
|
||||
m_enginePtr->m_barrier_PostCurr->wait(); // waiting on NS_Engine_Multithread::thread
|
||||
|
||||
for (size_t n=0;n<m_enginePtr->m_RunEngine->GetExtensionCount();++n)
|
||||
m_enginePtr->m_RunEngine->GetExtension(n)->Apply2Current();
|
||||
|
||||
m_enginePtr->ApplyCurrentExcite();
|
||||
|
||||
m_enginePtr->m_barrier_CurrExcite->wait(); // continue NS_Engine_Multithread::thread
|
||||
}
|
||||
|
||||
//DBG().cout() << "Thread e_excitation (" << boost::this_thread::get_id() << ") finished." << endl;
|
||||
|
|
|
@ -82,6 +82,9 @@ public:
|
|||
static Engine_Multithread* New(const Operator* op, unsigned int numThreads = 0);
|
||||
virtual ~Engine_Multithread();
|
||||
|
||||
inline virtual FDTD_FLOAT& GetVolt( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return m_RunEngine->GetVolt(n,x,y,z); }
|
||||
inline virtual FDTD_FLOAT& GetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return m_RunEngine->GetCurr(n,x,y,z);}
|
||||
|
||||
virtual void setNumThreads( unsigned int numThreads );
|
||||
virtual void Init();
|
||||
virtual void Reset();
|
||||
|
@ -92,11 +95,15 @@ public:
|
|||
protected:
|
||||
Engine_Multithread(const Operator* op);
|
||||
boost::thread_group m_thread_group;
|
||||
boost::barrier *m_barrier1, *m_barrier2, *m_barrier3, *m_startBarrier, *m_stopBarrier;
|
||||
boost::barrier *m_startBarrier, *m_stopBarrier;
|
||||
boost::barrier *m_barrier_VoltUpdate, *m_barrier_VoltExcite, *m_barrier_PreVolt, *m_barrier_PostVolt;
|
||||
boost::barrier *m_barrier_CurrUpdate, *m_barrier_CurrExcite, *m_barrier_PreCurr, *m_barrier_PostCurr;
|
||||
volatile unsigned int m_iterTS;
|
||||
unsigned int m_numThreads; //!< number of worker threads
|
||||
volatile bool m_stopThreads;
|
||||
|
||||
Engine* m_RunEngine;
|
||||
|
||||
#ifdef ENABLE_DEBUG_TIME
|
||||
std::map<boost::thread::id, std::vector<double> > m_timer_list;
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,8 @@ void Engine_sse::Init()
|
|||
f4_curr = Create_N_3DArray_v4sf(numLines);
|
||||
volt = 0; // not used
|
||||
curr = 0; // not used
|
||||
|
||||
InitExtensions();
|
||||
}
|
||||
|
||||
void Engine_sse::Reset()
|
||||
|
@ -58,13 +60,14 @@ void Engine_sse::Reset()
|
|||
f4_curr = 0;
|
||||
}
|
||||
|
||||
void Engine_sse::UpdateVoltages()
|
||||
void Engine_sse::UpdateVoltages(unsigned int startX, unsigned int numX)
|
||||
{
|
||||
unsigned int pos[3];
|
||||
bool shift[2];
|
||||
f4vector temp;
|
||||
|
||||
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
|
||||
pos[0] = startX;
|
||||
for (unsigned int posX=0;posX<numX;++posX)
|
||||
{
|
||||
shift[0]=pos[0];
|
||||
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
|
||||
|
@ -106,15 +109,17 @@ void Engine_sse::UpdateVoltages()
|
|||
f4_volt[2][pos[0]][pos[1]][0].v *= Op->f4_vv[2][pos[0]][pos[1]][0].v;
|
||||
f4_volt[2][pos[0]][pos[1]][0].v += Op->f4_vi[2][pos[0]][pos[1]][0].v * ( f4_curr[1][pos[0]][pos[1]][0].v - f4_curr[1][pos[0]-shift[0]][pos[1]][0].v - f4_curr[0][pos[0]][pos[1]][0].v + f4_curr[0][pos[0]][pos[1]-shift[1]][0].v);
|
||||
}
|
||||
++pos[0];
|
||||
}
|
||||
}
|
||||
|
||||
void Engine_sse::UpdateCurrents()
|
||||
void Engine_sse::UpdateCurrents(unsigned int startX, unsigned int numX)
|
||||
{
|
||||
unsigned int pos[5];
|
||||
f4vector temp;
|
||||
|
||||
for (pos[0]=0;pos[0]<numLines[0]-1;++pos[0])
|
||||
pos[0] = startX;
|
||||
for (unsigned int posX=0;posX<numX;++posX)
|
||||
{
|
||||
for (pos[1]=0;pos[1]<numLines[1]-1;++pos[1])
|
||||
{
|
||||
|
@ -154,5 +159,6 @@ void Engine_sse::UpdateCurrents()
|
|||
f4_curr[2][pos[0]][pos[1]][numVectors-1].v *= Op->f4_ii[2][pos[0]][pos[1]][numVectors-1].v;
|
||||
f4_curr[2][pos[0]][pos[1]][numVectors-1].v += Op->f4_iv[2][pos[0]][pos[1]][numVectors-1].v * ( f4_volt[1][pos[0]][pos[1]][numVectors-1].v - f4_volt[1][pos[0]+1][pos[1]][numVectors-1].v - f4_volt[0][pos[0]][pos[1]][numVectors-1].v + f4_volt[0][pos[0]][pos[1]+1][numVectors-1].v);
|
||||
}
|
||||
++pos[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ protected:
|
|||
Engine_sse(const Operator_sse* op);
|
||||
const Operator_sse* Op;
|
||||
|
||||
virtual void UpdateVoltages();
|
||||
virtual void UpdateCurrents();
|
||||
virtual void UpdateVoltages(unsigned int startX, unsigned int numX);
|
||||
virtual void UpdateCurrents(unsigned int startX, unsigned int numX);
|
||||
|
||||
unsigned int numVectors;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ Operator::~Operator()
|
|||
Reset();
|
||||
}
|
||||
|
||||
Engine* Operator::CreateEngine()
|
||||
Engine* Operator::CreateEngine() const
|
||||
{
|
||||
Engine* eng = Engine::New(this);
|
||||
return eng;
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
static Operator* New();
|
||||
virtual ~Operator();
|
||||
|
||||
virtual Engine* CreateEngine();
|
||||
virtual Engine* CreateEngine() const;
|
||||
|
||||
virtual bool SetGeometryCSX(ContinuousStructure* geo);
|
||||
virtual ContinuousStructure* GetGeometryCSX() {return CSX;}
|
||||
|
@ -55,7 +55,10 @@ public:
|
|||
double GetTimestep() const {return dT;};
|
||||
double GetNumberCells() const;
|
||||
|
||||
//! Returns the number of lines as needed for post-processing etc. (for the engine, use GetOriginalNumLines)
|
||||
virtual unsigned int GetNumberOfLines(int ny) const {return numLines[ny];}
|
||||
//! Returns the number of lines as needed for the engine etc. (for post-processing etc, use GetOriginalNumLines)
|
||||
virtual unsigned int GetOriginalNumLines(int ny) const {return numLines[ny];}
|
||||
|
||||
void ShowStat() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ Operator_Cylinder::~Operator_Cylinder()
|
|||
Operator::Reset();
|
||||
}
|
||||
|
||||
Engine* Operator_Cylinder::CreateEngine()
|
||||
Engine* Operator_Cylinder::CreateEngine() const
|
||||
{
|
||||
//!create a confentional engine... cylinder special operations will be dealt by engine extentions
|
||||
Engine* eng = Engine::New(this);
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
static Operator_Cylinder* New();
|
||||
virtual ~Operator_Cylinder();
|
||||
|
||||
virtual Engine* CreateEngine();
|
||||
virtual Engine* CreateEngine() const;
|
||||
|
||||
virtual bool SetGeometryCSX(ContinuousStructure* geo);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ Operator_sse::~Operator_sse()
|
|||
Reset();
|
||||
}
|
||||
|
||||
Engine* Operator_sse::CreateEngine()
|
||||
Engine* Operator_sse::CreateEngine() const
|
||||
{
|
||||
//!create a special sse-engine
|
||||
Engine_sse* eng = Engine_sse::New(this);
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
static Operator_sse* New();
|
||||
virtual ~Operator_sse();
|
||||
|
||||
virtual Engine* CreateEngine();
|
||||
virtual Engine* CreateEngine() const;
|
||||
|
||||
inline virtual FDTD_FLOAT& GetVV( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return f4_vv[n][x][y][z%numVectors].f[z/numVectors]; }
|
||||
inline virtual FDTD_FLOAT& GetVI( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return f4_vi[n][x][y][z%numVectors].f[z/numVectors]; }
|
||||
|
|
|
@ -46,6 +46,7 @@ openEMS::openEMS()
|
|||
FDTD_Eng=NULL;
|
||||
PA=NULL;
|
||||
CylinderCoords = false;
|
||||
m_MultiThreading = false;
|
||||
Enable_Dumps = true;
|
||||
DebugMat = false;
|
||||
DebugOp = false;
|
||||
|
@ -105,7 +106,7 @@ bool openEMS::parseCommandLineArgument( const char *argv )
|
|||
else if (strcmp(argv,"--engine=multithreaded")==0)
|
||||
{
|
||||
cout << "openEMS - enabled multithreading" << endl;
|
||||
m_engine = EngineType_Multithreaded;
|
||||
m_MultiThreading = true;
|
||||
return true;
|
||||
}
|
||||
else if (strncmp(argv,"--numThreads=",13)==0)
|
||||
|
@ -252,7 +253,7 @@ int openEMS::SetupFDTD(const char* file)
|
|||
cout << "Creation time for operator: " << difftime(OpDoneTime,startTime) << " s" << endl;
|
||||
|
||||
//create FDTD engine
|
||||
if (m_engine==EngineType_Multithreaded)
|
||||
if (m_MultiThreading)
|
||||
{
|
||||
FDTD_Eng = Engine_Multithread::New(FDTD_Op,m_engine_numThreads);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool CylinderCoords;
|
||||
bool m_MultiThreading;
|
||||
|
||||
//! Number of Timesteps
|
||||
unsigned int NrTS;
|
||||
|
@ -59,7 +60,7 @@ protected:
|
|||
Engine* FDTD_Eng;
|
||||
ProcessingArray* PA;
|
||||
|
||||
enum EngineType {EngineType_Standard,EngineType_Multithreaded,EngineType_SSE};
|
||||
enum EngineType {EngineType_Standard, EngineType_SSE};
|
||||
EngineType m_engine;
|
||||
unsigned int m_engine_numThreads;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue