diff --git a/hw3/MS_Hybrid_dynamic.cpp b/hw3/MS_Hybrid_dynamic.cpp index 768dbd2..8552590 100644 --- a/hw3/MS_Hybrid_dynamic.cpp +++ b/hw3/MS_Hybrid_dynamic.cpp @@ -3,6 +3,7 @@ */ #include "mpi.h" +#include #include #include #include @@ -188,7 +189,8 @@ int main(int argc, char **argv) { #pragma omp for schedule(dynamic, 1) for (j = 0; j < height; j++) { - // printf("rank %d : (%d, %d)\n", rank, i, j); + if (rank == 1) + printf("thread %d , j = %d\n", omp_get_thread_num(), j); Compl z, c; double temp, lengthsq; int repeats; diff --git a/hw3/MS_MPI_dynamic.cpp b/hw3/MS_MPI_dynamic.cpp index 959f900..9242998 100644 --- a/hw3/MS_MPI_dynamic.cpp +++ b/hw3/MS_MPI_dynamic.cpp @@ -65,12 +65,14 @@ int main(int argc, char **argv) isEnable = false; /********* MPI MISSION START *********/ - + double start, end; int rank, size; + MPI_Init(&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &rank); MPI_Comm_size (MPI_COMM_WORLD, &size); - + start = MPI_Wtime(); + MPI_Status status; MPI_Request request[size]; Display *display; @@ -92,6 +94,7 @@ int main(int argc, char **argv) /* draw points */ int numPerTask = width / (size); + int points = 0; if (rank == size - 1) numPerTask += width % (size); @@ -177,6 +180,7 @@ int main(int argc, char **argv) recv(&i, 1, MPI_INT, ROOT); } while (i != -1) { + points++; for (int j = 0; j < height; j++) { // printf("rank %d : (%d, %d)\n", rank, i, j); Compl z, c; @@ -270,6 +274,8 @@ int main(int argc, char **argv) XDrawPoint (display, window, gc, i, j); } } + end = MPI_Wtime(); + printf("TIMER: rank %d time %.6lf points %d\n", rank, end - start, points); MPI_Finalize(); if (isEnable) sleep(5); diff --git a/hw3/MS_MPI_static.cpp b/hw3/MS_MPI_static.cpp index f45e069..c7bd497 100644 --- a/hw3/MS_MPI_static.cpp +++ b/hw3/MS_MPI_static.cpp @@ -41,6 +41,8 @@ bool isEnable = false; int main(int argc, char **argv) { + double start, end; + threads = atoi(argv[1]); atof(minX, 2); @@ -62,6 +64,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &rank); MPI_Comm_size (MPI_COMM_WORLD, &size); + start = MPI_Wtime(); MPI_Status status; Display *display; @@ -121,8 +124,7 @@ int main(int argc, char **argv) Pixel *pixel = new Pixel[numPerTask * height]; int curIndex = 0; int beginPos = rank != size - 1 ? - numPerTask * (rank) : (rank) * (numPerTask - (width % (size))); - + numPerTask * (rank) : (rank) * (numPerTask - (width % (size))); printf("rank %d -> begin = %d, numTasks = %d\n", rank, beginPos, numPerTask); int ansK = -1; @@ -173,6 +175,8 @@ int main(int argc, char **argv) // printf("rank %d send pixel...\n", rank); } else if (isEnable) { + int drawTimes = 2; + while (drawTimes--) for (int index = 0; index < curIndex; ++index) { XSetForeground (display, gc, 1024 * 1024 * (pixel[index].repeats % 256)); @@ -190,7 +194,7 @@ int main(int argc, char **argv) drawGraph.push_back(pixel[i]); delete [] pixel; } - int drawTimes = 2; + drawTimes = 2; while (drawTimes--) { for (int k = 0; k < drawGraph.size(); ++k) { int i = drawGraph[k].i; @@ -205,7 +209,12 @@ int main(int argc, char **argv) } delete [] pixel; + end = MPI_Wtime(); + printf("TIMER: rank %d time %.6lf points %d\n", rank, end - start, numPerTask); + MPI_Finalize(); if (isEnable) sleep(5); + + return 0; } diff --git a/hw3/MS_OpenMP_dynamic.cpp b/hw3/MS_OpenMP_dynamic.cpp index 3090df5..d9a079e 100644 --- a/hw3/MS_OpenMP_dynamic.cpp +++ b/hw3/MS_OpenMP_dynamic.cpp @@ -100,11 +100,15 @@ int main(int argc, char **argv) /* draw points */ int i, j; + int points[2000]; + memset(points, 0, sizeof(points)); #pragma omp parallel num_threads(threads) private(i, j) { - #pragma omp for schedule(dynamic, 1) + double start = omp_get_wtime(); + #pragma omp for schedule(dynamic, 1) nowait for(i=0; i