0
votes

I want to shorten the runtime of an lengthy image processing algorithm, which is applied to multiple images by using parallel processing with openMP.

The algorithm works fine with single or limited number (=2) of threads.

But: The parallel processing with openMP requires lots of memory, leading to out-of-memory-exceptions, when running with the maximum number of possible threads.

To resolve the issue, I replaced the "throwing of exceptions" with a "waiting for free memory" in case of low memory, leading to many (<= all) threads just waiting for free memory...

Is there any solution/tool/approach to dynamically maintain the memory or start threads depending on available memory?

1
If your single thread works fine, then why a multithreaded version should use so much more memory? It sounds like a design issue. We need more detail and a working example to be able to help you. - Davide Spataro
If you don't have enough memory to process multiple images at once, then parallelize your algorithm for processing a single image. - Daniel Langr
If this really is just wrapping omp parallel for round the whole of your code, why not just use a shell (or, better, Python) script to run multiple processes in parallel!? - Jim Cownie

1 Answers

0
votes

Try compiling your program 64-bit. 32-bit programs can only have up to 2^32 = about 4GB of memory. 64-bit programs can use significantly more (2^64 which is 18 exabytes). It's very easy to hit 4GB of memory these days.

Note that if you are using more RAM than you have available, your OS will have to page some memory to disk. This can hurt performance a lot. If you get to this point (where you are using a significant portion of RAM) and still have extra cores, you would have to go deeper into the algorithm to find a more granular section to parallelize.

If you for some reason can't switch to 64-bit, you can do multiprocessing (running multiple instances of a program) so each process will have up to 4GB. You will need to launch and coordinate the processes somehow. Depending on your needs, this could mean using simple command-line arguments or complicated inter-process communication (IPC). OpenMP doesn't do IPC, but Open MPI does. Open MPI is generally used for communication between many nodes on a network, but it can be set up to run concurrent instances on one machine.