Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

What I want to run a function that contains a for loop (supposed to run in parallel) in a parallel outer loop. So it looks like the following:

void myfunction(){
    ...
    #pragma omp parallel for
    for (int i=0;i<10;i++){
        do something...
    }
}


int main(){
    #pragma omp parallel for
    for(int i=0;i<5;i++){
        myfunction();
    }
}

Given the above code, I want to create 5 parallel threads for the loop in the main() function, and I want each of the 5 threads to create another K threads to run its own parallel for loop.

Although I know how to run nested for loops if the inner loop is not in a separate function, I cannot find a solution for this kind of problem.

In fact, this piece of code is for parallel 5 fold cross validation, where each fold has a for loop that should be parallelized.

Can anyone help me?

share|improve this question
    
Does this work with the function? If so, what's the real problem? – tadman Dec 4 at 8:56
    
@tadman Sorry, but I don't get your question. I first want to create 5 threads and then I want to run a parallel for loop for each thread, where each thread should run independently. – Mansumen Dec 4 at 8:58
    
Do you search ? – Stargateur Dec 4 at 9:34
    
@Stargateur I have already read the post you linked me to. But the problem is different from mine such that I have my inner for loop in a function. I tried what the post told me but I couldn't get the result that I intended. – Mansumen Dec 4 at 9:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.