Skip to content
Snippets Groups Projects
Commit d43fde3a authored by Agung Baptiso Sorlawan's avatar Agung Baptiso Sorlawan
Browse files

Fix printing performance:

parent b7523936
No related merge requests found
File added
No preview for this file type
...@@ -63,9 +63,6 @@ int main(int argc, char** argv) { ...@@ -63,9 +63,6 @@ int main(int argc, char** argv) {
} }
int NbElmts = atoi(argv[1]); //ukuran array utama int NbElmts = atoi(argv[1]); //ukuran array utama
FILE *fp;
fp = fopen("performance", "w+");
MPI_Init(NULL, NULL); MPI_Init(NULL, NULL);
int world_rank; int world_rank;
...@@ -107,7 +104,6 @@ int main(int argc, char** argv) { ...@@ -107,7 +104,6 @@ int main(int argc, char** argv) {
for(int i=0;i<world_size;i++) { for(int i=0;i<world_size;i++) {
memcpy(rand_all + (i * bucket_size), &sub_rand_nums_all[i], sizeof(int) * bucket_size); memcpy(rand_all + (i * bucket_size), &sub_rand_nums_all[i], sizeof(int) * bucket_size);
} }
} }
int *sub_rand_nums = malloc(sizeof(int) * bucket_size); int *sub_rand_nums = malloc(sizeof(int) * bucket_size);
...@@ -115,12 +111,15 @@ int main(int argc, char** argv) { ...@@ -115,12 +111,15 @@ int main(int argc, char** argv) {
double total_time = 0.0; double total_time = 0.0;
MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD);
/* Start timer */
total_time -= MPI_Wtime(); total_time -= MPI_Wtime();
MPI_Scatter(rand_all, bucket_size, MPI_INT, sub_rand_nums, MPI_Scatter(rand_all, bucket_size, MPI_INT, sub_rand_nums,
bucket_size, MPI_INT, 0, MPI_COMM_WORLD); bucket_size, MPI_INT, 0, MPI_COMM_WORLD);
int swap; int swap;
// Buble Sort // Buble Sort
for (int c = 0 ; c < ( bucket_size - 1 ); c++) for (int c = 0 ; c < ( bucket_size - 1 ); c++)
{ {
...@@ -136,8 +135,7 @@ int main(int argc, char** argv) { ...@@ -136,8 +135,7 @@ int main(int argc, char** argv) {
} }
total_time += MPI_Wtime(); total_time += MPI_Wtime();
/* End timer */
fprintf(fp, "%d = %f ms\n", world_rank, total_time*1000);
int *all_new = NULL; int *all_new = NULL;
...@@ -152,13 +150,14 @@ int main(int argc, char** argv) { ...@@ -152,13 +150,14 @@ int main(int argc, char** argv) {
for(int i=0;i<NbElmts;i++) { for(int i=0;i<NbElmts;i++) {
printf("%d, ",rand_nums[i]); printf("%d, ",rand_nums[i]);
} }
printf("\n");
printf("\n\n");
printf("Sorted Array : \n"); printf("Sorted Array : \n");
for(int i=0;i<NbElmts;i++) { for(int i=0;i<NbElmts;i++) {
printf("%d, ",all_new[i]); printf("%d, ",all_new[i]);
} }
printf("\n\n"); printf("\n\n");
printf("---PERFORMANCE---\n");
} }
MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD);
...@@ -169,10 +168,10 @@ int main(int argc, char** argv) { ...@@ -169,10 +168,10 @@ int main(int argc, char** argv) {
} }
free(sub_rand_nums); free(sub_rand_nums);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize(); MPI_Finalize();
fclose(fp); printf("Process-%d = %f \n",world_rank ,total_time * 1000);
return 0; return 0;
} }
1 = 0.429869 ms 0 = 0.060081 ms
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