Hey, i want to sort an array by using 4 processes in parallel.
i have 4 processes that should sort the same array.
i have to create 4 fork, and make a sort on the same array.
i am having an array, that i read from file-fd, in size. the number of elements is n.
i send it to a qsort that using comp function.
right now, i can sort the array in one processes, but i have to do it by 4 processes in parallel.
my idea was to regard the array as 4 subarrays, sort each of them, at the end to merge them.
but my problems are: i dont know how can i regard them as 4 arrays, by using this function, how can i "tell" each processes its boundaries?
The writing of merge function isnt so difficult, but right now i have much urgent problems..
my code:
Code:
01 rfile = read ( fd , array , size );
02 size_t n= st.st_size/sizeof array[0];
03 qsort(shm, n,atoi(argv[3]) , comp);
04 write(1, shm,st.st_size);
05 return 1;
06 }
07
08 int comp(const void * a,const void * B){
09 const int *the_a = a;
10 const int *the_b = b;
11 if (*the_a > *the_B) return 1;
12 else if (*the_a < *the_B) return -1;
13 else return 0;
14 }