Rank Sort Parallel Algorithm

General OpenMP discussion

Rank Sort Parallel Algorithm

Postby mike_ledis » Wed Oct 26, 2011 7:51 am

Hello! I tried to make a ranksort algorithm work parallel. When i am trying to compile the code i keep getting the following error: ranksortomp.c c:18:77 error expected ')' before numeric constant. My code is shown below.
Code: Select all
# include <stdlib.h>
# include <stdio.h>
# include <omp.h>
#define N 10
int main()
{
   
   int x[N], y[N];
   int i, j,k, my_num, my_place,startval,endval,rank;
   

   for (k=0; k<N; k++)
   {
      x[k] = N - i;
      y[k]=N-i;
   }

#pragma omp parallel for private(i, j, startval, endval, rank) shared(x, y, N)
{
    rank = omp_get_thread_num ( );
    startval = N*rank/N+1;
    endval =  N*(rank+1)/N;
 
  for (j=startval; j<endval; j++) {
    my_num = x[j];
     my_place = 0;
     for (i=0; i<N; i++)
    {
      if ( my_num > x[i] )
         my_place++;
      }
     y[my_place] = my_num;
   } 

   for (i=0; i<N; i++)
      printf("%d\n", y[i]);
         
   return 0;
}

Does anyone has any idea for my compilation error;
mike_ledis
 
Posts: 3
Joined: Wed Oct 26, 2011 7:41 am

Re: Rank Sort Parallel Algorithm

Postby hhj » Wed Oct 26, 2011 8:06 am

In line 18, the use of "parallel for" is incorrect since the statement followed is not a "for" loop. Try to just use "parallel", i.e.,
Code: Select all
#pragma omp parallel private(i, j, startval, endval, rank) shared(x, y, N)

I'd say the diagnosis printed from the compiler is not very useful or accurate for this case.
hhj
 
Posts: 16
Joined: Thu May 01, 2008 11:59 am

Re: Rank Sort Parallel Algorithm

Postby mike_ledis » Wed Oct 26, 2011 8:08 am

I removed 'for' statement but i keep getting this error! : 0 (
mike_ledis
 
Posts: 3
Joined: Wed Oct 26, 2011 7:41 am

Re: Rank Sort Parallel Algorithm

Postby hhj » Wed Oct 26, 2011 11:21 am

What compiler and compiler options did you use?
hhj
 
Posts: 16
Joined: Thu May 01, 2008 11:59 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 7 guests