new engine: multithreaded

pull/1/head
Sebastian Held 2010-03-26 12:57:52 +01:00
parent 79574aa3e6
commit c916059a30
5 changed files with 177 additions and 3 deletions

109
FDTD/engine_multithread.cpp Normal file
View File

@ -0,0 +1,109 @@
/*
* Copyright (C) 2010 Sebastian Held (sebastian.held@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 "engine_multithread.h"
#include "tools/array_ops.h"
Engine_Multithread::Engine_Multithread(Operator* op) : Engine(op)
{
}
Engine_Multithread::~Engine_Multithread()
{
}
void Engine_Multithread::Init()
{
Engine::Init();
}
void Engine_Multithread::Reset()
{
Engine::Reset();
}
bool Engine_Multithread::IterateTS(unsigned int iterTS)
{
unsigned int pos[3];
int exc_pos;
bool shift[3];
for (unsigned int iter=0;iter<iterTS;++iter)
{
//voltage updates
for (pos[0]=0;pos[0]<Op->numLines[0];++pos[0])
{
shift[0]=pos[0];
for (pos[1]=0;pos[1]<Op->numLines[1];++pos[1])
{
shift[1]=pos[1];
for (pos[2]=0;pos[2]<Op->numLines[2];++pos[2])
{
shift[2]=pos[2];
//do the updates here
//for x
volt[0][pos[0]][pos[1]][pos[2]] *= Op->vv[0][pos[0]][pos[1]][pos[2]];
volt[0][pos[0]][pos[1]][pos[2]] += Op->vi[0][pos[0]][pos[1]][pos[2]] * ( curr[2][pos[0]][pos[1]][pos[2]] - curr[2][pos[0]][pos[1]-shift[1]][pos[2]] - curr[1][pos[0]][pos[1]][pos[2]] + curr[1][pos[0]][pos[1]][pos[2]-shift[2]]);
//for y
volt[1][pos[0]][pos[1]][pos[2]] *= Op->vv[1][pos[0]][pos[1]][pos[2]];
volt[1][pos[0]][pos[1]][pos[2]] += Op->vi[1][pos[0]][pos[1]][pos[2]] * ( curr[0][pos[0]][pos[1]][pos[2]] - curr[0][pos[0]][pos[1]][pos[2]-shift[2]] - curr[2][pos[0]][pos[1]][pos[2]] + curr[2][pos[0]-shift[0]][pos[1]][pos[2]]);
//for x
volt[2][pos[0]][pos[1]][pos[2]] *= Op->vv[2][pos[0]][pos[1]][pos[2]];
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]]);
}
}
}
//soft voltage excitation here (E-field excite)
for (unsigned int n=0;n<Op->E_Exc_Count;++n)
{
exc_pos = (int)numTS - (int)Op->E_Exc_delay[n];
exc_pos*= (exc_pos>0 && exc_pos<(int)Op->ExciteLength);
// if (n==0) cerr << numTS << " => " << Op->ExciteSignal[exc_pos] << endl;
volt[Op->E_Exc_dir[n]][Op->E_Exc_index[0][n]][Op->E_Exc_index[1][n]][Op->E_Exc_index[2][n]] += Op->E_Exc_amp[n]*Op->ExciteSignal[exc_pos];
}
//current updates
for (pos[0]=0;pos[0]<Op->numLines[0]-1;++pos[0])
{
for (pos[1]=0;pos[1]<Op->numLines[1]-1;++pos[1])
{
for (pos[2]=0;pos[2]<Op->numLines[2]-1;++pos[2])
{
//do the updates here
//for x
curr[0][pos[0]][pos[1]][pos[2]] *= Op->ii[0][pos[0]][pos[1]][pos[2]];
curr[0][pos[0]][pos[1]][pos[2]] += Op->iv[0][pos[0]][pos[1]][pos[2]] * ( volt[2][pos[0]][pos[1]][pos[2]] - volt[2][pos[0]][pos[1]+1][pos[2]] - volt[1][pos[0]][pos[1]][pos[2]] + volt[1][pos[0]][pos[1]][pos[2]+1]);
//for y
curr[1][pos[0]][pos[1]][pos[2]] *= Op->ii[1][pos[0]][pos[1]][pos[2]];
curr[1][pos[0]][pos[1]][pos[2]] += Op->iv[1][pos[0]][pos[1]][pos[2]] * ( volt[0][pos[0]][pos[1]][pos[2]] - volt[0][pos[0]][pos[1]][pos[2]+1] - volt[2][pos[0]][pos[1]][pos[2]] + volt[2][pos[0]+1][pos[1]][pos[2]]);
//for x
curr[2][pos[0]][pos[1]][pos[2]] *= Op->ii[2][pos[0]][pos[1]][pos[2]];
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]]);
}
}
}
//soft current excitation here (H-field excite)
++numTS;
}
return true;
}

45
FDTD/engine_multithread.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2010 Sebastian Held (sebastian.held@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/>.
*/
#ifndef ENGINE_MULTITHREAD_H
#define ENGINE_MULTITHREAD_H
#include "operator.h"
#include "engine.h"
class Engine_Multithread : public Engine
{
friend class Processing;
friend class ProcessVoltage;
friend class ProcessCurrent;
friend class ProcessFields;
friend class ProcessFieldsTD;
public:
Engine_Multithread(Operator* op);
virtual ~Engine_Multithread();
virtual void Init();
virtual void Reset();
//!Iterate a number of timesteps
virtual bool IterateTS(unsigned int iterTS);
protected:
};
#endif // ENGINE_MULTITHREAD_H

View File

@ -31,7 +31,8 @@ SOURCES += main.cpp \
FDTD/processfields_td.cpp \ FDTD/processfields_td.cpp \
FDTD/processcurrent.cpp \ FDTD/processcurrent.cpp \
examples/FDTD_examples.cpp \ examples/FDTD_examples.cpp \
openems.cpp openems.cpp \
FDTD/engine_multithread.cpp
HEADERS += tools/ErrorMsg.h \ HEADERS += tools/ErrorMsg.h \
tools/AdrOp.h \ tools/AdrOp.h \
tools/constants.h \ tools/constants.h \
@ -44,4 +45,5 @@ HEADERS += tools/ErrorMsg.h \
FDTD/processfields_td.h \ FDTD/processfields_td.h \
FDTD/processcurrent.h \ FDTD/processcurrent.h \
examples/FDTD_examples.h \ examples/FDTD_examples.h \
openems.h openems.h \
FDTD/engine_multithread.h

View File

@ -20,6 +20,7 @@
#include "tools/array_ops.h" #include "tools/array_ops.h"
#include "FDTD/operator.h" #include "FDTD/operator.h"
#include "FDTD/engine.h" #include "FDTD/engine.h"
#include "FDTD/engine_multithread.h"
#include "FDTD/processvoltage.h" #include "FDTD/processvoltage.h"
#include "FDTD/processcurrent.h" #include "FDTD/processcurrent.h"
#include "FDTD/processfields_td.h" #include "FDTD/processfields_td.h"
@ -95,6 +96,12 @@ bool openEMS::parseCommandLineArgument( const char *argv )
DebugOperator(); DebugOperator();
return true; return true;
} }
else if (strcmp(argv,"--engine=multithreaded")==0)
{
cout << "openEMS - enabled multithreading" << endl;
m_engine = EngineType_Multithreaded;
return true;
}
return false; return false;
} }
@ -217,7 +224,15 @@ int openEMS::SetupFDTD(const char* file)
cout << "Creation time for operator: " << difftime(OpDoneTime,startTime) << " s" << endl; cout << "Creation time for operator: " << difftime(OpDoneTime,startTime) << " s" << endl;
//create FDTD engine //create FDTD engine
switch (m_engine) {
case EngineType_Multithreaded:
FDTD_Eng = new Engine_Multithread(FDTD_Op);
break;
default:
FDTD_Eng = new Engine(FDTD_Op); FDTD_Eng = new Engine(FDTD_Op);
break;
}
time_t currTime = time(NULL); time_t currTime = time(NULL);

View File

@ -52,6 +52,9 @@ protected:
Operator* FDTD_Op; Operator* FDTD_Op;
Engine* FDTD_Eng; Engine* FDTD_Eng;
ProcessingArray* PA; ProcessingArray* PA;
enum EngineType {EngineType_Standard,EngineType_Multithreaded};
EngineType m_engine;
}; };
#endif // OPENEMS_H #endif // OPENEMS_H