How can I speed up a recursive code using OpenMP? Basically, I have to speed up the S function in the program here. The code is as below.
void S(Oct* oct, unsigned int l) {
S(oct, l+1);
A(oct, l);
S(oct, l+1);
AR(oct,l);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Looking at your code, I would say the code is not parallelizable. Since S() is a recursive function, adding openmp pragma inside the function would lead to overhead of creating threads. It wouldn’t really improve the performance. Moreover, you shouldn’t parallelize those other functions, A() and AR(), as well. It will also create the same overhead performance problem.
I would suggest either to parallelize the source code that invokes S() in the first place, or to break down the code to eliminate recursion (then you might have a possibility to parallelize using openmp).