the task is as follows:
Write a program that takes as parameters a set of data file names (an arbitrary number) and runs all files for parallel processing (using threads). As a processing, use the sorting method (quickSort).
I ran this program through vmbox on the QNX operating system.It has compiled but does nothing.I have a text file with numbers in my project folder and nothing happens to them.or there should be several of them..(i mean files)And one more thing. I get one warning when compiling. After this sign }
, which "closes" the void *FileToArray
The warning is as follows: control reaches end of non-void function.How to fix it?
I did it on the basis of methodological guidelines.But maybe I missed something. And I would be grateful if you could tell me what I'm doing wrong.
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/syspage.h>
void quickSort (int *b,int left, int right){
int sort;
int Dleft = left;
int Dright = right;
sort = b[left];
printf ("%d",pthread_self());
while(left<right){
while((b[right]>=sort)&&(left<right))
right--;
if (left!=right){
b[left]=b[right];
left++;
}
while((b[left]<=sort)&&(left<right))
left++;
if(left!=right)
{
b[right]=b[left];
right --;
}
}
b[left]=sort;
sort=left;
left=Dleft;
right=Dright;
if(left<sort)
quickSort(b,left,sort-1);
if(right>sort)
quickSort(b,sort+1,right);
}
void *FileToArray(void *name){
int i =0,j =0;
int *a=(int*)malloc(sizeof(int)*2);
FILE *f=fopen(name,"r");
printf("start - %p\n",name);
while (feof(f)==0){
fscanf(f, "%d",&a[i]);
i++;
a=(int*)realloc(a,sizeof(int)*i+1);
}
fclose(f);
quickSort(a,0,i-2);
f=fopen(name,"w");
for (j=0;j<i-1;j++){
fprintf(f, "%d\n",a[j]);
}
free(a);
fclose(f);
printf("finish - %p\n",name);
}
int num_lines_per_cpu;
int num_cpus;
int main(int argc, char** argv) {
int j;
pthread_t *thread_ids;
num_cpus = syspage_ptr->num_cpu;
thread_ids=malloc(sizeof(pthread_t)*num_cpus);
num_lines_per_cpu=argc%num_cpus;
for(j=1;j<argc;j++){
pthread_create (&thread_ids[j-1],NULL,FileToArray,argv[j]);
}
for(j=0;j<argc-1;j++){
pthread_join(thread_ids[j],NULL);
}
return EXIT_SUCCESS;
}