I am experimenting with openMP for large data processing and relatively new to it. My input data set is huge and so I divided it into multiple subsets and each thread working on the subset of data. Each dataitem in the subset is acted up on by the thread. If one of the threads fails during its operation on any dataitem, i would like to terminate other threads and return a failure. Using shared variable is an option, but is there a better way to do the same ?
views:
28answers:
1What do you want to happen if one of your threads chokes on its input ? Do you want to bring the program to a sudden halt ? Or do you want to stop the parallel execution and have a serial part of the program tidy up ?
OpenMP is not really designed for either kind of operation, so you're going to be struggling against it, rather than struggling with it as most beginners do. You certainly could, as you suggest, use shared variables and write your own logic to stop the program or jump to the end of the parallel region if one of the threads fails. But there are no OpenMP intrinsic mechanisms for these operations.
You might want to investigate the new task
capabilities of OpenMP 3.0. Using these you can certainly implement a system whereby tasks are dispatched to threads which return either success or failure, and have other tasks which deal with failures.
Finally, one might argue that bad input should not cause a program to crash, but that's another topic.