diff --git a/a b/a index 530e3c15ceeaea09bb140e8f812cefd9353a441b..a922c98cb31e14d2f4705a7d60fb03b1c99e14c8 100755 Binary files a/a and b/a differ diff --git a/tes.c b/tes.c index d1f860b069e84bc48592ae1af0380acdafa5a351..036c8bd0dda20e25a3e5b93353d62a099ada1478 100644 --- a/tes.c +++ b/tes.c @@ -16,7 +16,7 @@ float *create_rand_nums(int num_elements) { // n adalah jumlah element float *insertion_sort(float array[], int n) { - float tarray[n]; + float *tarray = (float *)malloc(sizeof(float) * n); int d,c,t; for (c = 1 ; c <= n - 1; c++) { d = c; @@ -29,6 +29,7 @@ float *insertion_sort(float array[], int n) { d--; } } + int i; for (i = 0 ; i < n; i++) { tarray[i] = array[i]; @@ -52,12 +53,13 @@ int main(int argc, char** argv) { int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); - int num_elements_per_proc = world_size; - + int num_elements_per_proc = num_elements / world_size; + printf("%d\n",world_size); float *rand_nums = NULL; if (world_rank == 0) { rand_nums = create_rand_nums(num_elements); } + int i; for (i = 0; i < num_elements; i++) { printf("BBB %f \n", rand_nums[i]); @@ -66,9 +68,19 @@ int main(int argc, char** argv) { float *sub_rand_nums = (float *)malloc(sizeof(float) * num_elements_per_proc); assert(sub_rand_nums != NULL); - MPI_Scatter(rand_nums, num_elements_per_proc, MPI_FLOAT, sub_rand_nums, num_elements_per_proc, MPI_FLOAT, 0, MPI_COMM_WORLD); + MPI_Scatter(rand_nums, num_elements, MPI_FLOAT, sub_rand_nums, num_elements_per_proc, MPI_FLOAT, 0, MPI_COMM_WORLD); + + for (i = 0; i < num_elements; i++) { + printf("CCC %f\n",sub_rand_nums[i]); + } + + printf("AADADADAD\n"); - float *sub_rand_numss = insertion_sort(sub_rand_nums, num_elements_per_proc); + float *sub_rand_numss = insertion_sort(sub_rand_nums, num_elements_per_proc); + for (i = 0; i < 3; i++) { + printf("AAAA %f\n",sub_rand_numss[i]); + } + float *sub_avgs = NULL; if (world_rank == 0) { @@ -76,9 +88,7 @@ int main(int argc, char** argv) { assert(sub_avgs != NULL); } - for (i = 0; i < 3; i++) { - printf("AAAA %f\n",sub_rand_numss[i]); - } + //MPI_Gather(&sub_avg, 1, MPI_FLOAT, sub_avgs, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); //Concat