Hi,
I am attempting to use OpenMP in my project that contains N agents in a simulation. Every agent has a position vector. Inside my program, I do something like the following:
for(int i=0;i<agents.size();i++){
for(int j=0;j<agents.size();j++){
if(i==j) continue;
if(distance_between(i,j)<10){
//do a lot of calculations for interaction between i and j,
//and a bunch of changes to variables of the Agents stored in the list
}
}
}
Am I able to simply prepend "#pragma omp parallel for" in front of the first loop to distribute the work? If I do it, my program runs much faster, but I am concerned that the calculations it is doing may not be accurate.
The order of these calculations does not matter, as long as every i,j pair is processed, and no variable outside of the variables defined inside the innermost loop, and the variables in my Agents class are ever changed (only read).
Not being a systems guy I have trouble understanding inner workings of OpenMP, and have become slightly suspicious of it. Thanks for any help with this!