dimanche 12 avril 2015

N-ary search program in C using openmp is giving error when thread count is less than 4


Vote count:

0




This is program for n-ary search . When we give no. of threads less than 4 , it says core dumped (Segmentation fault).But if thread count is 4 or more than 4 it works successfully giving reults. CODE::



#include<stdio.h>
#include<omp.h>
//#include<timer.h>
int a[65536],s,test;
int global_size,global_x,n;

void nary_search(int,int);
main()
{
int i,size=65536,x=0;

for(i=0;i<size;i++)
a[i]=i;
printf("Enter number to be searched\n");
scanf("%d",&s);
printf("enter the number of threads used\n");
scanf("%d",&n);


nary_search(size,x);




}



void nary_search(int size,int x)
{
printf("size = %d\n",size);
if(size<=n)
{

test=0;
#pragma omp parallel
{
int tid=omp_get_thread_num();
if(a[global_x+tid]==s)
{

printf("found at %d\n",global_x+tid);
test=1;
}
}

if(test==0)
{

printf("not found\n");
}
}
else
{
test=0;
#pragma omp parallel
{
int tid=omp_get_thread_num();
printf("checking (%d -- %d)with thread %d on cpu %d \n",a[tid*size/n+x],a[tid*size/n+size/n-1+x],tid,sched_getcpu());
if(s>=a[tid*size/n+x] && s<=a[tid*size/n+size/n-1+x])
{
printf("may be here %d ---- %d size=( %d )\n",a[tid*size/n+x],a[tid*size/n+size/n-1+x],+size/n);
global_size=size/n;
global_x=tid*global_size+x;
test=1;
}
}
if(test==1)
nary_search(global_size,global_x);
else
printf("not found in");
}
}


Can anybody help with this error ?



asked 30 secs ago







N-ary search program in C using openmp is giving error when thread count is less than 4

Aucun commentaire:

Enregistrer un commentaire