Using preCICE in a multi-threaded environment


can preCICE be used in a multi-threaded environment? Especially the code snippets dealing with read and write functionality readVectorData and writeVectorData could gain a substantial benefit using a parallel shared memory environment. The function readVectorData is also declared as const so that I may assume that the read-only access is also valid for multiple threads at the same time.

That’s a tough one.
What you definitely can do and what others have done previously is to use the solver on all threads, but preCICE only on one thread (per distributed node). For most applications, this is “efficient enough”.

If you want to use preCICE on all threads you have to do all preCICE calls for all threads and specify the thread rank and size in the SolverInterface constructor.
AFAIK, this has simply never been tested, but would be interesting to find out if it just works or not. Maybe a thread-safe MPI implementation would then be necessary? If it works, performance is a whole different story then again.

That’s not really feasible in the current implementation, since only parts of the whole code are multi-threaded and the threads are teared down during the serial parts.

All in all, I tried to use multiple threads for the readVectorData function, although it has only been initialized once and it doesn’t work out. There is probably one critical section in the function call since it runs for a certain amount of time before I obtain a memory corruption and the program terminates. Still, I’m not sure about the reason… However, I can also read the data block-wise in serial using readBlockVectorData and apply the same parallelization scheme using the obtained “block vector” as source vector and it works.
Locking the readVectorData call using a mutex worked also, but requires overall more synchronization across the threads.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.