sorting - Bitonicsort C code segmentation issue -


i running bitonic sort sequential code on machine. runs fine array size upto 16 elements increase size 32 gives following error while execution:

" warning: process 654 terminated: segmentation fault (11)."

can me whats appening?? occupies alot of memory when size increased 32 why problem appearing??

i want test parallel version. so, need array size of considerable length comparison..

following code:

void merge_up(int *arr, int n) { int step=n/2,i,j,k,temp;  while (step > 0)         {                  (i=0; < n; i+=step*2)                 {                         (j=i,k=0;k < step;j++,k++)                         {                                         if (arr[j] > arr[j+step])                                         { // swap                                                 temp = arr[j];                                                 arr[j]=arr[j+step];                                                 arr[j+step]=temp;                                         }                         }                 }                 step /= 2;         } }  void merge_down(int *arr, int n) {          int step=n/2,i,j,k,temp;                 while (step > 0)                 {                         (i=0; < n; i+=step*2)                         {                                 (j=i,k=0;k < step;j++,k++)                                 {       if (arr[j] < arr[j+step])                                         {       // swap                                                 temp = arr[j];                                                 arr[j]=arr[j+step];                                                 arr[j+step]=temp;                                         }                                 }                         }                         step /= 2;                 } }  int main(int argc, char **argv) {  int n, i, s; n = 32;  int arr[32] = {234, 233, 22, 1, 22, 8, 1, 89, 5, 34, 21, 9, 222, 2, 1, 999, 21, 12, 23, 32, 21, 111, 45, 23, 211, 21, 232, 45, 22, 11, 9876, 22, 2, 3, 555, 333};  printarray(arr,n);  // merges (s=2; s <= n; s*=2) {         (i=0; < n;)         {                 merge_up((arr+i),s);                 merge_down((arr+i+s),s);                 += s*2;         } }  printarray(arr,n);  }// end   void printarray(int *arr, int n) {          int i;         printf("[%d",arr[0]);  (i=1; < n;i++)         {                 printf(",%d",arr[i]);         }         printf("]\n"); } 

i think overlooking

warning: excess elements in array initializer 

your arr initialized 32 elements , trying push elements on limit.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -