-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get the number of threads within an operator extension #126
Comments
This is not how the multithreading logic works in openEMS. According to the current design, an extension itself should not launch any thread. It's the responsibility of the engine to launch threads. Instead, an extension should implement the API For an example, if an extension has 100 workitems in single-thread mode:
To add multithreading support to this extension, first, implement the function
See the source code of But I suggestion is not to worry too much about the threading issue. I'm (still) in the process of completely rewrite the multithread logic in my new openEMS Tiling engine, which would make all of what I've said become obsolete ;-) |
Hey @biergaizi, Thank you for taking the time to respond. I'll try to elaborate my problem further. If you look at the example you sent me, the method void Engine_Ext_UPML::SetNumberOfThreads(int nrThread)
{
Engine_Extension::SetNumberOfThreads(nrThread);
m_numX = AssignJobs2Threads(m_Op_UPML->m_numLines[0],m_NrThreads,false);
m_start.resize(m_NrThreads,0);
m_start.at(0)=0;
for (size_t n=1; n<m_numX.size(); ++n)
m_start.at(n) = m_start.at(n-1) + m_numX.at(n-1);
} Are only called in one place:
The next logical step, naturally, was to look which class\function\member contains the data I needed. The answer was pretty straight forward. Line 254 in 1ccf094
Which later invokes (I think) this: Line 632 in 1ccf094
As I wrote earlier, I later tried to access the I didn't want to fiddle with that too much at this point, so I did a very dirty bypass. The rest, I did as you suggested: void Engine_Ext_Absorbing_BC::SetNumberOfThreads(int nrThread)
{
Engine_Extension::SetNumberOfThreads(nrThread);
// This command assigns the number of jobs (primitives) handled by each thread
v_primsPerThread = AssignJobs2Threads(m_numPrims,m_NrThreads,false);
// Basically cumsum. Starting point of each thread.
v_threadStartPrim.resize(m_NrThreads,0);
v_threadStartPrim.at(0) = 0;
for (size_t threadIdx = 1; threadIdx < v_threadStartPrim.size(); threadIdx++)
v_threadStartPrim.at(threadIdx) = v_threadStartPrim.at(threadIdx - 1) + v_primsPerThread.at(threadIdx - 1);
}
void Engine_Ext_Absorbing_BC::DoPreVoltageUpdates(int threadID)
{
// if (IsActive()==false) return;
if (m_Eng==NULL) return;
if (threadID >= m_NrThreads)
return;
uint pos[] = {0,0,0};
uint pos0[] = {0,0,0};
uint pos1[] = {0,0,0};
uint pos_shift[] = {0,0,0};
uint dir[] = {0,0,0};
uint primIdx = 0;
uint cellCtr;
for (uint primCtr = 0 ; primCtr < v_primsPerThread.at(threadID) ; primCtr++)
{
// current primitive index for this thread
primIdx = primCtr + v_threadStartPrim.at(threadID);
(etc, etc). I don't know if this is an actual issue or just me misusing the multi-threading structure. Cheers |
I am building a new operator and engine extension right now (again) that handles large groups of mesh cells.
While trying to speed up the run, I attempted to utilize multiple threads.
However, I couldn't find a way to query the number of threads in the simulation from within the operator\engine. I couldn't befriend the
Operator_Multithread
class, as there was a conflict in theupdate_openEMS.sh
script. They are "unaware" of each other during the linking stage.I reverted, eventually to add another constructor that accepts the number of threads in
openEMS::SetupFDTD
I would a appreciate if there is a suggestion for a more elegant solution.
PS
I did see ~25% speedup with the multi-threaded version I ran, so there is motivation for this.
The text was updated successfully, but these errors were encountered: