void multisort(long n, T data[n], T tmp[n]) {
    if (n >= MIN_SORT_SIZE*4L) {
        // Recursive decomposition
        
        #pragma omp task depend(out:data[0:n/4L])
        multisort(n/4L, &data[0], &tmp[0]);
        
        #pragma omp task depend(out:data[n/4L:n/4L])
        multisort(n/4L, &data[n/4L], &tmp[n/4L]);
        
        #pragma omp task depend(out:data[n/2L:n/4L])
        multisort(n/4L, &data[n/2L], &tmp[n/2L]);
        
        #pragma omp task depend(out:data[3L*n/4L:n/4L])
        multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);

        
        
        #pragma omp task depend(in:data[0:n/4L], data[n/4L:n/4L]) depend(out:tmp[0:n/2L])
        merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);
            
        #pragma omp task depend(in:data[n/2L:n/4L], data[3L*n/4L:n/4L]) depend(out:tmp[n/2L:n/2L])
        merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);
        
        #pragma omp task depend(in:tmp[0:n/2L], tmp[n/2L:n/2L])
        merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);
        
        #pragma omp taskwait
        
    } else {
        // Base case
        basicsort(n, data);
    }
}
Beispiel #2
0
void multisort(long n, T data[n], T tmp[n])
{
	if (n >= MIN_SORT_SIZE*4L) {
		// Recursive decomposition
		#pragma omp task 
		multisort(n/4L, &data[0], &tmp[0]);
		#pragma omp task 
		multisort(n/4L, &data[n/4L], &tmp[n/4L]);
		#pragma omp task 
		multisort(n/4L, &data[n/2L], &tmp[n/2L]);
		#pragma omp task 
		multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);


		#pragma omp task 
		merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);
		#pragma omp task 
		merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);
		

		#pragma omp task 
		merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);
	} else {
		// Base case
		basicsort(n, data);
	}
}
void multisort(long n, T data[n], T tmp[n]) {
        if (n >= MIN_SORT_SIZE*4L) {
                // Recursive decomposition


		#pragma omp task depend(out: data[0:n/4L])
                multisort(n/4L, &data[0], &tmp[0]);
		#pragma omp task depend(out: data[n/4L:n/4L])
                multisort(n/4L, &data[n/4L], &tmp[n/4L]);
		#pragma omp task depend(out: data[n/2L:n/4L])
                multisort(n/4L, &data[n/2L], &tmp[n/2L]);
		#pragma omp task depend(out: data[3L*n/4L:n/4L])
                multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);

		#pragma omp task depend(in: data[0:n/4L], data[n/4L:n/4L]) depend(out: tmp[0:n/2L])
                merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);
		#pragma omp task depend(in: data[n/2L:n/4L], data[3L*n/4L:n/4L]) depend(out: tmp[n/2L:n/2L])
                merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);

		#pragma omp task depend(in: tmp[0:n/2L], tmp[n/2L:n/2L])
                merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);
		#pragma omp taskwait
	} else {
		// Base case
#if _EXTRAE_
		Extrae_event(PROGRAM, SORT);
#endif
		basicsort(n, data);
#if _EXTRAE_
		Extrae_event(PROGRAM, END);
#endif
	}
}
Beispiel #4
0
void multisort(long n, T data[n], T tmp[n]) {
       
        if (n >= MIN_SORT_SIZE*4L) {
                // Recursive decomposition

	        tareador_start_task("RecursiveMultisort");
	       
                multisort(n/4L, &data[0], &tmp[0]);

                multisort(n/4L, &data[n/4L], &tmp[n/4L]);

                multisort(n/4L, &data[n/2L], &tmp[n/2L]);

                multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);

                merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);
                merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);

                merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);

	        tareador_end_task("RecursiveMultisort");;

	} else {
		// Base case
                tareador_start_task("BaseCaseMultisort");
		basicsort(n, data);
                tareador_end_task("BaseCaseMultisort");
	}

}
Beispiel #5
0
int main(int argc, char **argv) {
 	int success;

	if (argc != 4) {
		fprintf(stderr, "Usage: %s <vector size in K> <seq sort size in K> <seq merge size in K>\n", argv[0]);
		return 1;
	}

	N = atol(argv[1]) * 1024L;
	MIN_SORT_SIZE = atol(argv[2]) * 1024L;
	MIN_MERGE_SIZE = atol(argv[3]) * 1024L;
	
	T *data = malloc(N*sizeof(T));
	T *tmp = malloc(N*sizeof(T));
	
	double init_time = omp_get_wtime();
	initialize(N, data);
	touch(N, tmp);
	init_time = omp_get_wtime() - init_time;

	double sort_time = omp_get_wtime();
	multisort(N, data, tmp);
   sort_time = omp_get_wtime() - sort_time;

	success = check_solution(N, data);
	if (!success) printf ("SORTING FAILURE\n"); 
	else printf ("SORTING SUCCESS\n"); 

   fprintf(stdout, "Multisort program (using %d threads)\n", omp_get_num_threads() );
   fprintf(stdout, "   Initialization time in seconds = %g\n", init_time);
   fprintf(stdout, "   Multisort time in seconds = %g\n", sort_time);
   fprintf(stdout, "\n");

	return 0;
}
Beispiel #6
0
int main(int argc, char **argv) {

        if (argc != 4) {
                fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]);
                return 1;
        }

	N = atol(argv[1]) * BLOCK_SIZE;
	MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE;
        MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE;
	
	T *data = malloc(N*sizeof(T));
	T *tmp = malloc(N*sizeof(T));
	
	initialize(N, data);
	clear(N, tmp);

	tareador_ON();
   	multisort(N, data, tmp);
	tareador_OFF();

   	check_sorted (N, data);

    	fprintf(stdout, "Multisort program finished\n");
	return 0;
}
Beispiel #7
0
void multisort(int *a, int start, int end)
{
    int n = end - start;
    if (n <= 256)
    {
        countsort(a, start, n/2);
        countsort(a, n/2 + 1, end);
        mergesort(a, start, end);
    }
    else
    {
        multisort(a, start, n/2);
        multisort(a, n/2 + 1, end);
        mergesort(a, start, end);
    }
}
Beispiel #8
0
void do_sort(long n, T data[n], T tmp[n]) {

#if _EXTRAE_
   Extrae_event(PROGRAM, MULTISORT);
#else
   double sort_time = omp_get_wtime();
#endif

   #pragma omp parallel
   #pragma omp single
   multisort(N, data, tmp);

#if _EXTRAE_
   Extrae_event(PROGRAM,END);
#else
   sort_time = omp_get_wtime() - sort_time;
   fprintf(stdout, "%g\n", sort_time);
#endif

#if _EXTRAE_
   Extrae_event(PROGRAM,CHECK);
#endif
   check_sorted (N, data);
#if _EXTRAE_
   Extrae_event(PROGRAM,END);
#endif
}
void multisort(long n, T data[n], T tmp[n]) {
	if (n >= MIN_SORT_SIZE*4L) {
		// Recursive decomposition
		multisort(n/4L, (T *) &data[0], (T *) &tmp[0]);
		multisort(n/4L, (T *) &data[n/4L], (T *) &tmp[n/4L]);
		multisort(n/4L, (T *) &data[n/2L], (T *) &tmp[n/2L]);
		multisort(n/4L, (T *) &data[3L*n/4L], (T *) &tmp[3L*n/4L]);   
        
		merge_rec(n/4L, (T *) &data[0], (T *) &data[n/4L], (T *) &tmp[0], 0, n/2L);
		merge_rec(n/4L, (T *) &data[n/2L], (T *) &data[3L*n/4L], (T *) &tmp[n/2L], 0, n/2L);
        
		merge_rec(n/2L, (T *) &tmp[0], (T *) &tmp[n/2L], (T *) &data[0], 0, n);
        
    } else {
		// base case
		basicsort(n, (T *) &data[0]);
    }
}
void multisort(long n, T data[n], T tmp[n]) {
        if (n >= MIN_SORT_SIZE*4L) {
                // Recursive decomposition

		#pragma omp taskgroup
		{
		#pragma omp task
                multisort(n/4L, &data[0], &tmp[0]);
		#pragma omp task
                multisort(n/4L, &data[n/4L], &tmp[n/4L]);
		#pragma omp task
                multisort(n/4L, &data[n/2L], &tmp[n/2L]);
		#pragma omp task
                multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);
		}

		#pragma omp taskgroup
		{
		#pragma omp task
                merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);
		#pragma omp task
                merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);
		}

                merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);
	} else {
		// Base case
#if _EXTRAE_
		Extrae_event(PROGRAM, SORT);
#endif
		basicsort(n, data);
#if _EXTRAE_
		Extrae_event(PROGRAM, END);
#endif
	}
}
int main(int argc, char **argv) {
	N = 16L * (1024L * 1024L);
	MIN_SORT_SIZE = 8L * 1024L;
	MIN_MERGE_SIZE = 4L * MIN_SORT_SIZE;
	
	// Data
	T *data, *tmp, *reference;
	posix_memalign((void **)&data, sizeof(T)*N, sizeof(T)*N);
	posix_memalign((void **)&tmp, sizeof(T)*N, sizeof(T)*N);
	posix_memalign((void **)&reference, sizeof(T)*N, sizeof(T)*N);
	
	
	#pragma css start
	long initializionSize = N/4L, i; //N/32L, i;
	for (i = 0; i < N; i += initializionSize) {
		long length = initializionSize;
		if (i+length > N) {
			length = N - i;
		}
		zz_initialize(length, (T (*)) (&data[i]));
	}
	for (i = 0; i < N; i += initializionSize) {
		long length = initializionSize;
		if (i+length > N) {
			length = N - i;
		}
		zz_touch(length, (T *) &data[i], (T *) &tmp[i]);
	}
	#pragma css barrier
	
	memcpy(reference, data, sizeof(T)*N);
    
	multisort(N, data, tmp);
	#pragma css finish
    
	qsort(reference, N, sizeof(T), qsort_helper);
    
	if (memcmp(reference, data, sizeof(T)*N) == 0) {
		return 0;
	} else {
		printf("FAILED\n");
		return 1;
	}
}
int main(int argc, char **argv) {
    
    if (argc != 4) {
        fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]);
        return 1;
    }
    
    N = atol(argv[1]) * BLOCK_SIZE;
    MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE;
    MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE;
    
    T *data = malloc(N*sizeof(T));
    T *tmp = malloc(N*sizeof(T));
    
    double stamp;
    START_COUNT_TIME;
    
    initialize(N, data);
    clear(N, tmp);
    
    STOP_COUNT_TIME("Initialization time in seconds");
    
   	START_COUNT_TIME;
    
    #pragma omp parallel
    #pragma omp single
   	multisort(N, data, tmp);
    
   	STOP_COUNT_TIME("Multisort execution time");
    
   	START_COUNT_TIME;
    
   	check_sorted (N, data);
    
   	STOP_COUNT_TIME("Check sorted data execution time");
    
    fprintf(stdout, "Multisort program finished\n");
    return 0;
}
Beispiel #13
0
int main(void)
{
    int j = 0;
    int i = 0;
    clock_t t1_start;
    clock_t t2_start;
    clock_t t1_end;
    clock_t t2_end;
    float t1;
    float t2;

    printf("Beginning...\n");
    for (j = 0; j < 20; j++)
    {
        a = (int*)malloc(1000*sizeof(int));
        b = (int*)malloc(1000*sizeof(int));
        for (i = 0; i < 1000; i++)
        {
            a[i] = rand() % 10;
        }
        memcpy(a, b, 1000*sizeof(int));
        printf("Test #%d: ||", j+1);
        t1_start = clock();
        multisort(a, 0, 1000 - 1);
        t1_end = clock();
        t1 = (double)(t1_end - t1_start);
        printf("MSort Time: %f ||", t1);
        t2_start = clock();
        qsort(b, 1000, sizeof(int), cmp);
        t2_end = clock();
        t2 = (double)(t2_end - t2_start);
        printf("QSort Time: %f ||\n", t2);
        free(a);
        free(b);
    }
    return 0;
}
int main(int argc, char **argv) {

        if (argc != 4) {
                fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]);
                return 1;
        }

	N = atol(argv[1]) * BLOCK_SIZE;
	MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE;
        MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE;

	T *data = malloc(N*sizeof(T));
	T *tmp = malloc(N*sizeof(T));
	
#if _EXTRAE_
        Extrae_init();
	Extrae_event(PROGRAM, INITIALIZE);
#else
        double stamp;
        START_COUNT_TIME;
#endif

	initialize(N, data);
	clear(N, tmp);

#if _EXTRAE_
	Extrae_event(PROGRAM, END);
#else
        STOP_COUNT_TIME("Initialization time in seconds");
#endif

#if _EXTRAE_
   	Extrae_event(PROGRAM, MULTISORT);
#else
   	START_COUNT_TIME;
#endif
        #pragma omp parallel
        #pragma omp single
        {
   	multisort(N, data, tmp);
        }
#if _EXTRAE_
   	Extrae_event(PROGRAM,END);
#else
   	STOP_COUNT_TIME("Multisort execution time");
#endif

#if _EXTRAE_
   	Extrae_event(PROGRAM,CHECK);
#else
   	START_COUNT_TIME;
#endif

   	check_sorted (N, data);

#if _EXTRAE_
   	Extrae_event(PROGRAM,END);
        Extrae_fini();
#else
   	STOP_COUNT_TIME("Check sorted data execution time");
#endif

    	fprintf(stdout, "Multisort program finished\n");
	return 0;
}
//sort the data by length, then alphabetized by calling private sort functions
void SortingCompetition::sortData(){

    multisort(0,getWordCount()-1, 3);


}
Beispiel #16
0
void multisort(long n, T data[n], T tmp[n]) {       
 if (n >= MIN_SORT_SIZE*4L) {
                // Recursive decomposition

		// Una tasca de tareador por cada llamada
#if _TAREADOR_
		tareador_start_task("multisort1");
#endif
                multisort(n/4L, &data[0], &tmp[0]);
#if _TAREADOR_
		tareador_end_task();
		tareador_start_task("multisort2");
#endif
                multisort(n/4L, &data[n/4L], &tmp[n/4L]);
#if _TAREADOR_
		tareador_end_task();
		tareador_start_task("multisort3");
#endif
                multisort(n/4L, &data[n/2L], &tmp[n/2L]);

#if _TAREADOR_
		tareador_end_task();
		tareador_start_task("multisort4");
#endif
                multisort(n/4L, &data[3L*n/4L], &tmp[3L*n/4L]);
#if _TAREADOR_
		tareador_end_task();
		tareador_start_task("merge1");
#endif
                merge(n/4L, &data[0], &data[n/4L], &tmp[0], 0, n/2L);

#if _TAREADOR_
                tareador_end_task();
                tareador_start_task("merge2");    
#endif
                merge(n/4L, &data[n/2L], &data[3L*n/4L], &tmp[n/2L], 0, n/2L);
#if _TAREADOR_
                tareador_end_task();
                tareador_start_task("merge3");    
#endif
                merge(n/2L, &tmp[0], &tmp[n/2L], &data[0], 0, n);
#if _TAREADOR_
                tareador_end_task();    
#endif

	} else {
		// Base case
#if _EXTRAE_
		Extrae_event(PROGRAM, SORT);
#endif
#if _TAREADOR_
		tareador_start_task("basesort");
#endif
		basicsort(n, data);
#if _TAREADOR_
		tareador_end_task();
#endif
#if _EXTRAE_
		Extrae_event(PROGRAM, END);
#endif
	}
}