Problem with PARALLEL SECTIONS

General OpenMP discussion

Problem with PARALLEL SECTIONS

Postby rbanos » Mon May 07, 2012 5:11 am

Hello,
I parallelize the serial code (this code works correctly):

****************************************************************************************************
for(indiv=0;indiv<I_numero_individuos/3;indiv++) {
construir_solucion_inicial_First_Fit(indiv);
}
for(indiv=I_numero_individuos/3;indiv<(2*I_numero_individuos/3);indiv++) {
construir_solucion_inicial_First_Fit_Random(indiv);
}
for(indiv=(2*I_numero_individuos/3);indiv<I_numero_individuos;indiv++) {
construir_solucion_inicial_First_Fit_Random(indiv);
}
****************************************************************************************************

by using the parallel sections (a segmentation fault is produced):

****************************************************************************************************
#pragma omp parallel sections private(indiv)
{
#pragma omp section
{
for(indiv=0;indiv<I_numero_individuos/3;indiv++) {
construir_solucion_inicial_First_Fit(indiv);
printf("\n I am %d and I have called to First Fit for the individual %d.",omp_get_thread_num(),indiv);
}
}
#pragma omp section
{
for(indiv=I_numero_individuos/3;indiv<(2*I_numero_individuos/3);indiv++) {
construir_solucion_inicial_First_Fit_Random(indiv);
printf("\n I am %d and I have called to First Fit Random for the individual %d.",omp_get_thread_num(),indiv);
}
}
#pragma omp section
{
for(indiv=(2*I_numero_individuos/3);indiv<I_numero_individuos;indiv++) {
construir_solucion_inicial_First_Fit_Random(indiv);
printf("\n I am %d and I have called to First Fit Random for the individual %d.",omp_get_thread_num(),indiv);
}
}
}
#pragma omp barrier
****************************************************************************************************

Can anybody help me to find the error?
Thanks,
Raul
rbanos
 
Posts: 3
Joined: Mon Apr 23, 2012 5:36 am

Re: Problem with PARALLEL SECTIONS

Postby ftinetti » Wed May 09, 2012 7:44 pm

Hi Raul,

I think it should be something inside functions
construir_solucion_inicial_First_Fit(indiv);
construir_solucion_inicial_First_Fit_Random(indiv);

BTW, two of the three sections call the same function, and the code below works fine.
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>

void construir_solucion_inicial_First_Fit(int indiv);
void construir_solucion_inicial_First_Fit_Random(int indiv);

main()
{
  int indiv, I_numero_individuos = 6;


  #pragma omp parallel sections private(indiv)
  {
    #pragma omp section
    {
      for(indiv=0;indiv<I_numero_individuos/3;indiv++)
      {
        construir_solucion_inicial_First_Fit(indiv);
        printf("\n I am %d and I have called to First Fit for the individual %d.\n",omp_get_thread_num(),indiv);
      }
    }
    #pragma omp section
    {
      for(indiv=I_numero_individuos/3;indiv<(2*I_numero_individuos/3);indiv++)
      {
        construir_solucion_inicial_First_Fit_Random(indiv);
        printf("\n I am %d and I have called to First Fit Random for the individual %d.\n",omp_get_thread_num(),indiv);
      }
    }
    #pragma omp section
    {
      for(indiv=(2*I_numero_individuos/3);indiv<I_numero_individuos;indiv++)
      {
        construir_solucion_inicial_First_Fit_Random(indiv);
        printf("\n I am %d and I have called to First Fit Random for the individual %d.\n",omp_get_thread_num(),indiv);
      }
    }
  }
}

//---------------------------------------------------------------
void construir_solucion_inicial_First_Fit(int indiv)
{
  printf("Hi from  construir_solucion_inicial_First_Fit(%d)\n", indiv);
}

//---------------------------------------------------------------
void construir_solucion_inicial_First_Fit_Random(int indiv)
{
  printf("Hi from construir_solucion_inicial_First_Fit_Random(%d)\n", indiv);
}


The problem inside any (or both) of those functions could range from not enough memory for the stack to data races and/or access to shared data... hard to say... I would suggest calling the same function in the three sections just to check if the problem lies in one of them, both, or the current combination of calls. Later, well... check inside each function.

HTH,

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: Problem with PARALLEL SECTIONS

Postby MarkB » Mon May 14, 2012 11:42 am

Are you calling a random number generator inside those functions? If so, there's a very good chance it is not thread safe....
MarkB
 
Posts: 481
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 13 guests