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
ResidueDB not thread safe. #905
Comments
actually, I am more worried here about the buildResidueNames_ part, that also seems to change the state of the singleton. Maybe it would be smarter to wrap the whole |
I think for rmost application it is fine to wrap addResidue_(). |
correct me if I'm wrong, but calling a const-function does not guarantee correct behaviour if at the same time a non-const (wrapped in critical or not) is changing the underlying data structure.... |
yep you are right. e.g. reallocation of a container would be an example |
there is multiple routes to this (there might be more):
|
my 2 cents (as a omp neewb):
|
One common solution that I know is uses widely in the linux kernel are spinlocks. One would need a write lock and each thread would first have to acquire a lock before an operation. There is only one write lock and while one thread is using the lock, no other thread may either read or write. Since this will be only a short amount of time, the thread will simply execute a furtunately, OpenMP already supplies some locking to some extend:
even though it does not allow our "many can read, only one can write" scenario. One implementation I found for this was here This way, it is ensured that no reader is writing while a writer is writing and also that a writer actually gets to write at some point by acquiring one read-lock at a time. I wonder why this is so complicated, it seems that other people must have had the same problem before, but apparently there is no generic solution available as far as I can see. |
sounds good and the last link seems to provide reasonable code. |
the problem seems to be real: at least I get errors like:
occassionally when processing modified peptides with -threads 10 I'm pretty sure that's an iterator invalidated by reallocation. |
Timo, could you provide a simple test example producing the error, based on this we could test different solutions. I would assume that readers/writer lock is the most sensible solution, but we would need to implement by hand. Any volunteers? |
@timosachsenberg does this only happen in multithreaded settings? are the exceptions caught inside or outside the OpenMP loop? |
So far only happens in multithreaded setting. Sorry, did not find time to put together a test. Something like calling AASequence::fromString("TEST[" + String(number) + "]PEPTIDE" in omp parallel for using a range of doubles should reproduce it. It is definitly thrown inside the loop but I have to check where it is caught (I think its the global exception handler but I'm not sure - why is this important?). |
its important because catching exceptions outside the OpenMP loops are not supported while catching them inside the loop should (in theory) be fine. However in OpenMS there seem to be issues with multi threaded exception handling due to the singletons we use when doing that. Basically, uou can use exceptions inside parallel regions. But they mustn't leave these parallel regions. See also https://software.intel.com/en-us/blogs/2009/11/05/openmp-and-exceptions |
Related to #957 |
Can this be closed based in #3993 or not yet? |
e.g. parsing of AASequences containing modifications with multiple threads causes segmentation faults.
Reason is that modified residues are implicitly added to the ResidueDB singleton if they don't exist.
#5 0x00007ffff6b95586 in OpenMS::Map<OpenMS::String, OpenMS::Map<OpenMS::String, OpenMS::Residue*> >::operator[](this=0x7678e8, key=...)
#6 0x00007ffff6b92179 in OpenMS::ResidueDB::addResidue_ (this=0x7670b0, r=0x7fffdc004400) at /abi-data/sachsenb/OpenMS_IDE/src/openms/source/CHEMISTRY/ResidueDB.cpp:161
#7 0x00007ffff6b94aae in OpenMS::ResidueDB::getModifiedResidue (this=0x7670b0, residue=0x846070, modification=...)
#8 0x00007ffff6b5b00a in OpenMS::AASequence::setModification (this=0x7fffdc004ad0, index=16, modification=...)
#9 0x00007ffff70a8be9 in OpenMS::ModifiedPeptideGenerator::applyFixedModifications (fixed_mods_begin=..., fixed_mods_end=..., peptide=...)
#10 0x0000000000497534 in SimpleSearchEngine::main_ (.omp_data_i=0x7fffffffaf40) at /abi-data/sachsenb/OpenMS_IDE/src/utils/SimpleSearchEngine.cpp:582
#11 0x00007ffff400ae3a in gomp_thread_start (xdata=) at ../.././libgomp/team.c:115
#12 0x00000033854079d1 in start_thread () from /lib64/libpthread.so.0
#13 0x00000030bd2e8b6d in clone () from /lib64/libc.so.6
The text was updated successfully, but these errors were encountered: