1

I'm doing a code to solve a integro-diferencial equation, and this equation have a parameter that i want to see how affects my solution, when running a for loop in the serial version i have a list of result, but when running the code using omp sections to split the loop in two, the firs half is the same, but the second changed after de third decimal place, but i need the same result.

What can i do to solve this?

Serial version

for (int i = 0; i < vetores; i++)
{
   eta = 1.0;
   D   = 1.0;
   K = (double) i*1.0;
    
   K_vetor[i] = calculo(theta,theta_zero,omega,x,t,eta,D,K,g,f);
    
   printf("K %d\n",i);

}

Openmp version

#pragma omp parallel default(none) shared(x,omega,K_vetor,vetores) firstprivate(theta_zero,theta,theta2,theta3,t) private(eta,D,K)  //private(i,aux,temp1,temp2) 
{
    #pragma omp sections nowait
    {
        #pragma omp section
        {
            for (int i = 0; i < vetores/2; i++)
            {
                eta = 1.0;
                D   = 1.0;
                K = (double) i*1.0;
                
                K_vetor[i] = calculo(theta,theta_zero,omega,x,t,eta,D,K,g,f);
                
                printf("K %d\n",i);

            }
        }
        #pragma omp section
        {
            for (int i = vetores/2; i < vetores; i++)
            {
                eta = 1.0;
                D   = 1.0;
                K = (double) i*1.0;
                
                K_vetor[i] = calculo(theta2,theta_zero,omega,x,t,eta,D,K,g,f);
                
                printf("K %d\n",i);

            }
        }
    }
}

Diff output

OMP                                 Serial
0 0.406062                          0 0.406062
1 0.910302                          1 0.910302
2 0.95234                           2 0.95234
3 0.935899                          3 0.935899
4 0.845607                          4 0.845607
5 0.800523                          5 0.800523
6 0.784356                         |6 0.785621
7 0.771353                         |7 0.771651
8 0.742191                         |8 0.742313
9 0.764885                         |9 0.76473
10 0.774907                        |10 0.775604
11 0.776134                        |11 0.77482
12 0.817413                        |12 0.813391

Obs: All my variables are double.

Some images of theta and theta2

theta and theta2 for one oscilator

theta and theta2 for another oscilator

pedro12374
  • 11
  • 3

0 Answers0