Skip to content
Snippets Groups Projects
Commit 9c766df0 authored by omarcelh's avatar omarcelh
Browse files

not done

parent 729bc0e6
No related merge requests found
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
int main(int argc, char** argv){
int numtasks, rank, dest, source, rc, count, tag=1;
numtasks = strtol(argv[1], NULL, 10);
int bucketNEff;
int bucketsNEff[numtasks];
int i;
int n;
int *arr;
int *input;
double sendtime=0.0 , sorttime=0.0;
int min,max;
srand(time(NULL));
printf("Input number of element");
n = strtol(argv[2], NULL, 10);
input=(int*)malloc(sizeof(int)*n);
printf("%d number of elements\n", n);
int c;
for (c = 0; c < n; c++) {
input[c] = abs(rand() % 1000000);
printf("%d. %d\n", c, input[c]);
}
min = input[0];
max = input[0];
for (c = 0; c < n; c++) {
if(input[c] < min) {
min = input[c];
}
if(input[c] > max) {
max = input[c];
}
}
}
printf("numtasks: %d\n", numtasks);
int j;
for(j=1; j<numtasks; j++){
bucketsNEff[j] = 0;
}
for(i=0; i<n; i++){
int inc = max/(numtasks-1);
int iteration = 1;
int k;
int p = 0; //false
for(k=inc; k<=max; k+=inc){
if(input[i] <= k){
bucketsNEff[iteration]++;
p = 1;
break;
}
iteration++;
}
if(!p){
bucketsNEff[iteration-1]++;
}
}
#pragma omp parallel for num_threads(numtasks)
for(i=0; i<numtasks; i++){
int c, d, t;
for (c = 1 ; c <= n; c++) {
d = c;
while ( d > 0 && input[d] < input[d-1]) {
t = input[d];
input[d] = input[d-1];
input[d-1] = t;
d--;
}
}
}
printf("\nAvg send time = %lf\n", sendtime / numtasks);
printf("Avg sort time = %lf\n", sorttime / numtasks);
}
return 0;
}
omp_hello 0 → 100755
File added
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void Hello(void); /* Thread function */
int main(int argc, char *argv[]) {
int thread_count = strtol(argv[1], NULL, 10);
#pragma omp parallel num_threads(thread_count)
Hello();
return 0;
}
void Hello(void) {
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("Hello from thread %d of %d\n",
my_rank, thread_count);
}
omp_sort 0 → 100755
File added
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
void insertionSort(int* arr, int size, int** sortedArr);
void bucketSort(int* arr, int size, int** sortedArr);
int main(int argc, char** argv){
int bucketNEff;
int thread_count = strtol(argv[1], NULL, 10);
int bucketsNEff[thread_count];
int* arr_final;
int* input;
//double sendtime=0.0 , sorttime=0.0;
//int min,max;
srand(time(NULL));
int n = strtol(argv[2], NULL, 10);
input = (int*) malloc (sizeof(int)*n);
printf("%d number of elements\n", n);
int c;
for (c = 0; c < n; c++) {
input[c] = abs(rand() % 1000000);
printf("%d. %d\n", c, input[c]);
}
# pragma omp parallel num_threads(thread_count)
bucketSort(input, n, &arr_final);
for(c=0; c<n; c++){
printf("%d ", arr_final[c]);
}
/*
min = input[0];
max = input[0];
for (c = 0; c < n; c++) {
if(input[c] < min) {
min = input[c];
}
if(input[c] > max) {
max = input[c];
}
}*/
return 0;
}
void insertionSort(int* arr, int size, int** sortedArr){
int c, d, t;
*sortedArr = (int*) malloc (sizeof(int) * size);
for(c=0; c<size; c++){
*sortedArr[c] = arr[c];
}
for (c = 1 ; c <= size - 1; c++) {
d = c;
while ( d > 0 && arr[d] < arr[d-1]) {
t = *sortedArr[d];
*sortedArr[d] = *sortedArr[d-1];
*sortedArr[d-1] = t;
d--;
}
}
}
void bucketSort(int* arr, int size, int** sortedArr){
int c;
*sortedArr = (int*) malloc (sizeof(int) * size);
for(c=0; c<size; c++){
sortedArr[c] = arr[c];
}
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
double range = size/thread_count;
int i_awal, i_akhir;
i_awal = my_rank * range;
i_akhir = i_awal + range;
int temp[range];
int i;
for(i=0; i<range; i++){
temp[i] = arr[
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment