Skip to content
Snippets Groups Projects
Commit c59a81c6 authored by 13513046's avatar 13513046
Browse files

time count added

parent 956c4c12
No related merge requests found
...@@ -9,7 +9,7 @@ int *create_rand_nums(int num_elements) { ...@@ -9,7 +9,7 @@ int *create_rand_nums(int num_elements) {
assert(rand_nums != NULL); assert(rand_nums != NULL);
int i; int i;
for (i = 0; i < num_elements; i++) { for (i = 0; i < num_elements; i++) {
rand_nums[i] = rand(); rand_nums[i] = rand() % num_elements;
} }
return rand_nums; return rand_nums;
} }
...@@ -37,6 +37,8 @@ int main(int argc, char** argv) { ...@@ -37,6 +37,8 @@ int main(int argc, char** argv) {
int bucket[world_size][total_elements]; int bucket[world_size][total_elements];
int *rand_nums = NULL; int *rand_nums = NULL;
double time_start, time_stop;
if (world_rank == 0) { if (world_rank == 0) {
rand_nums = create_rand_nums(total_elements); rand_nums = create_rand_nums(total_elements);
for (i = 0; i < total_elements; i++) { for (i = 0; i < total_elements; i++) {
...@@ -46,6 +48,7 @@ int main(int argc, char** argv) { ...@@ -46,6 +48,7 @@ int main(int argc, char** argv) {
min = rand_nums[i]; min = rand_nums[i];
} }
range = (max - min) / world_size + ((max - min) % world_size > 0); range = (max - min) / world_size + ((max - min) % world_size > 0);
time_start = MPI_Wtime();
for (i = 0; i < world_size; i++) { for (i = 0; i < world_size; i++) {
k = 0; k = 0;
for (j = 0; j < total_elements; j++) { for (j = 0; j < total_elements; j++) {
...@@ -59,8 +62,14 @@ int main(int argc, char** argv) { ...@@ -59,8 +62,14 @@ int main(int argc, char** argv) {
} }
rc = MPI_Send(bucket[i], total_elements+1, MPI_INT, i, 1, MPI_COMM_WORLD); rc = MPI_Send(bucket[i], total_elements+1, MPI_INT, i, 1, MPI_COMM_WORLD);
} }
for (i = 1 ; i < total_elements; i++) { for (i = 1 ; i < total_elements-1; i++)// {
j = i; for (j = i; j < total_elements; j++)
if (bucket[0][i] > bucket[0][j]) {
int temp = bucket[0][i];
bucket[0][i] = bucket[0][j];
bucket[0][j] = temp;
}
/*j = i;
while ( j > 0 && bucket[0][j] < bucket[0][j-1]) { while ( j > 0 && bucket[0][j] < bucket[0][j-1]) {
t = bucket[0][j]; t = bucket[0][j];
...@@ -69,11 +78,18 @@ int main(int argc, char** argv) { ...@@ -69,11 +78,18 @@ int main(int argc, char** argv) {
j--; j--;
} }
} }*/
} else { } else {
rc = MPI_Recv(inmsg, total_elements+1, MPI_INT, 0, 1, MPI_COMM_WORLD, &Stat); rc = MPI_Recv(inmsg, total_elements+1, MPI_INT, 0, 1, MPI_COMM_WORLD, &Stat);
//Sort //Sort
for (i = 1 ; i < total_elements; i++) { for (i = 0; i < total_elements-1; i++)
for (j = i+1; j < total_elements; j++)
if (inmsg[i] > inmsg[j]) {
int temp = inmsg[i];
inmsg[i] = inmsg[j];
inmsg[j] = temp;
}
/* for (i = 1 ; i < total_elements; i++) {
j = i; j = i;
while ( j > 0 && inmsg[j] < inmsg[j-1]) { while ( j > 0 && inmsg[j] < inmsg[j-1]) {
...@@ -83,7 +99,7 @@ int main(int argc, char** argv) { ...@@ -83,7 +99,7 @@ int main(int argc, char** argv) {
j--; j--;
} }
} } */
rc = MPI_Send(inmsg, total_elements+1, MPI_INT, 0, 1, MPI_COMM_WORLD); rc = MPI_Send(inmsg, total_elements+1, MPI_INT, 0, 1, MPI_COMM_WORLD);
} }
if (world_rank == 0) { if (world_rank == 0) {
...@@ -103,9 +119,12 @@ int main(int argc, char** argv) { ...@@ -103,9 +119,12 @@ int main(int argc, char** argv) {
} }
} }
} }
time_stop = MPI_Wtime() - time_start;
} }
if (world_rank == 0) { if (world_rank == 0) {
free(rand_nums); free(rand_nums);
printf("%d processes, %d elements, %.2lf seconds", world_size, total_elements, time_stop);
} }
MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD);
......
bucksort 0 → 100755
File added
#daftar host
167.205.35.26
167.205.35.28
167.205.35.29
167.205.35.30
#167.205.35.31
#167.205.35.32
#167.205.35.33
#167.205.35.34
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