Skip to content
Snippets Groups Projects
Commit aeb3479c authored by 13512501's avatar 13512501
Browse files

add pengukur waktu di openmp.c

parent 811609c2
No related merge requests found
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "random.c" #include "random.c"
#include "insertion_sort_func.c" #include "insertion_sort_func.c"
void sort(int * arr, int len){ void sort(int * arr, int len){
insertion_sort(arr,len); insertion_sort(arr,len);
} }
int main(int argc, char ** argv){ int main(int argc, char ** argv){
...@@ -21,11 +22,16 @@ int main(int argc, char ** argv){ ...@@ -21,11 +22,16 @@ int main(int argc, char ** argv){
exit(1); exit(1);
} }
clock_t start, end, total;
int thread_count =strtol(argv[1],NULL,10); int thread_count =strtol(argv[1],NULL,10);
int * compl_arr; int * compl_arr;
int i,j; int i,j;
int num_elmts; int num_elmts;
//input //input
scanf("%d",&num_elmts); scanf("%d",&num_elmts);
...@@ -39,11 +45,11 @@ int main(int argc, char ** argv){ ...@@ -39,11 +45,11 @@ int main(int argc, char ** argv){
printf("%d ", compl_arr[i]); printf("%d ", compl_arr[i]);
} }
printf("\n"); printf("\n");
start = clock();
//bagi-bagi //bagi-bagi
int * num_elmts_in_buckets; int * num_elmts_in_buckets;
int * buckets_bin; int * buckets_bin;
int ** buckets; int ** buckets;
num_elmts_in_buckets = (int*) malloc(thread_count*sizeof(int)); num_elmts_in_buckets = (int*) malloc(thread_count*sizeof(int));
buckets = (int**) malloc(thread_count*sizeof(int*)); buckets = (int**) malloc(thread_count*sizeof(int*));
...@@ -79,12 +85,14 @@ int main(int argc, char ** argv){ ...@@ -79,12 +85,14 @@ int main(int argc, char ** argv){
//copy //copy
memcpy(&compl_arr[bucket_offset[i]],buckets[i],num_elmts_in_buckets[i]*sizeof(int)); memcpy(&compl_arr[bucket_offset[i]],buckets[i],num_elmts_in_buckets[i]*sizeof(int));
} }
end = clock();
total = end - start;
for (i=0;i<num_elmts;i++){ for (i=0;i<num_elmts;i++){
printf("%d ", compl_arr[i]); printf("%d ", compl_arr[i]);
} }
printf("\n"); printf("\n");
printf("Total waktu %f",(double)total/CLOCKS_PER_SEC);
free(bucket_offset); free(bucket_offset);
free(num_elmts_in_buckets); free(num_elmts_in_buckets);
for (i=0;i<thread_count;i++) for (i=0;i<thread_count;i++)
......
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