diff --git a/HW7/.idea/workspace.xml b/HW7/.idea/workspace.xml index 1025b0b..f808fad 100644 --- a/HW7/.idea/workspace.xml +++ b/HW7/.idea/workspace.xml @@ -35,7 +35,12 @@ - + + + + + + + @@ -85,6 +92,7 @@ 1584397992559 + @@ -96,9 +104,55 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HW7/a.out b/HW7/a.out new file mode 100755 index 0000000..08f571b Binary files /dev/null and b/HW7/a.out differ diff --git a/HW7/cmake-build-debug/CMakeFiles/main.dir/CXX.includecache b/HW7/cmake-build-debug/CMakeFiles/main.dir/CXX.includecache new file mode 100644 index 0000000..2187b08 --- /dev/null +++ b/HW7/cmake-build-debug/CMakeFiles/main.dir/CXX.includecache @@ -0,0 +1,36 @@ +#IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) + +#IncludeRegexScan: ^.*$ + +#IncludeRegexComplain: ^$ + +#IncludeRegexTransform: + +/Users/bradybodily/Repositories/CS5500_Parallel_Prog/HW7/main.cpp +iostream +- +mpi.h +- +stdlib.h +- +unistd.h +- +time.h +- +queue +- + +/usr/local/Cellar/open-mpi/4.0.3/include/mpi.h +stddef.h +- +mpi_portable_platform.h +/usr/local/Cellar/open-mpi/4.0.3/include/mpi_portable_platform.h +openmpi/ompi/mpi/cxx/mpicxx.h +/usr/local/Cellar/open-mpi/4.0.3/include/openmpi/ompi/mpi/cxx/mpicxx.h + +/usr/local/Cellar/open-mpi/4.0.3/include/mpi_portable_platform.h +omp.h +/usr/local/Cellar/open-mpi/4.0.3/include/omp.h +omp.h +/usr/local/Cellar/open-mpi/4.0.3/include/omp.h + diff --git a/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.internal b/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.internal new file mode 100644 index 0000000..5dafadc --- /dev/null +++ b/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.internal @@ -0,0 +1,7 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.15 + +CMakeFiles/main.dir/main.cpp.o + /Users/bradybodily/Repositories/CS5500_Parallel_Prog/HW7/main.cpp + /usr/local/Cellar/open-mpi/4.0.3/include/mpi.h + /usr/local/Cellar/open-mpi/4.0.3/include/mpi_portable_platform.h diff --git a/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.make b/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.make index 7e75fee..672c1e5 100644 --- a/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.make +++ b/HW7/cmake-build-debug/CMakeFiles/main.dir/depend.make @@ -1,2 +1,7 @@ -# Empty dependencies file for main. -# This may be replaced when dependencies are built. +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.15 + +CMakeFiles/main.dir/main.cpp.o: ../main.cpp +CMakeFiles/main.dir/main.cpp.o: /usr/local/Cellar/open-mpi/4.0.3/include/mpi.h +CMakeFiles/main.dir/main.cpp.o: /usr/local/Cellar/open-mpi/4.0.3/include/mpi_portable_platform.h + diff --git a/HW7/cmake-build-debug/CMakeFiles/main.dir/main.cpp.o b/HW7/cmake-build-debug/CMakeFiles/main.dir/main.cpp.o new file mode 100644 index 0000000..fc04aab Binary files /dev/null and b/HW7/cmake-build-debug/CMakeFiles/main.dir/main.cpp.o differ diff --git a/HW7/cmake-build-debug/main b/HW7/cmake-build-debug/main index ab97687..d2d2a76 100755 Binary files a/HW7/cmake-build-debug/main and b/HW7/cmake-build-debug/main differ diff --git a/HW7/main.cpp b/HW7/main.cpp index 452892d..28157db 100644 --- a/HW7/main.cpp +++ b/HW7/main.cpp @@ -1,18 +1,13 @@ #include #include #include -#include #include #include #define MCW MPI_COMM_WORLD -#define ANY MPI_ANY_SOURCE -#define IGNORE MPI_STATUS_IGNORE -#define BLACK 0 -#define WHITE 1 +#define GENERIC 0 +#define SPECIAL 1 #define JOB 1 #define TOKEN 2 -#define CREATED 3 -#define COMPLETED 4 using namespace std; @@ -22,8 +17,8 @@ int main(int argc, char **argv) { int tasksCreated = 0; int tasksCompleted = 0; int taskLimit; - int tokenColor = WHITE; - int myColor = WHITE; + int tokenValue = SPECIAL; + int myToken = SPECIAL; int newTask; bool hasToken = false; queue myTasks; @@ -44,18 +39,15 @@ int main(int argc, char **argv) { MPI_Send(&job, 1, MPI_INT, rand() % 4, JOB, MCW); //Send out the initial job } - while(1) { - MPI_Probe(ANY,JOB,MCW,&status); - MPI_Recv(&newTask,1,MPI_INT,ANY,JOB,MCW,&status); - myTasks.push(newTask); - //MPI_IProbe(ANY, JOB, MCW, &jobFlag, &status); //Check to see if a job is available -// if(jobFlag) { -// MPI_Irecv(&newTask, 1, MPI_INT, ANY, JOB, MCW, &request); -// myTasks.push(newTask); -// } + while(true) { + MPI_Iprobe(MPI_ANY_SOURCE, JOB, MCW, &jobFlag, &status); //Check to see if a job is available + if(jobFlag) { + MPI_Irecv(&newTask, 1, MPI_INT, MPI_ANY_SOURCE, JOB, MCW, &request); + myTasks.push(newTask); + } if(newTask == -1) { //If the stop signal is received, send my info to process 0 and break out of the loop - MPI_Send(&tasksCreated, 1, MPI_INT, 0, CREATED, MCW); - MPI_Send(&tasksCompleted, 1, MPI_INT, 0, COMPLETED, MCW); + MPI_Send(&tasksCreated, 1, MPI_INT, 0, size-1, MCW); + MPI_Send(&tasksCompleted, 1, MPI_INT, 0, size, MCW); break; } if(myTasks.size() > 16) { //If my task queue is greater than size 16, send off 2 tasks @@ -63,59 +55,67 @@ int main(int argc, char **argv) { int task = myTasks.front(); myTasks.pop(); int dest = rand() % 4; - while(dest == rank) {dest = rand() % 4;} - if(dest < rank) {myColor = BLACK;} + while(dest == rank) {dest = rand() % size;} + if(dest < rank) { myToken = GENERIC;} MPI_Send(&task, 1, MPI_INT, dest, JOB, MCW); } } - if(!myTasks.empty()) { //Perform a task + if(!myTasks.empty()) { int num = myTasks.front(); myTasks.pop(); - sleep(static_cast(num)/5); + num^3-num^4; tasksCompleted++; } - if(tasksCreated < taskLimit) { //Create more tasks - for(int i = 0; i < rand() % 3 + 1; i++) { - myTasks.push(rand() % 3 + 1); + if(tasksCreated < taskLimit) { + for(int i = 0; i < rand() % size; i++) { + myTasks.push(rand() % size); tasksCreated++; } } if(myTasks.empty()) { //Check the token information if(hasToken) { - cout<<"Rank: "<= 0 ? rank - 1 : size - 1; MPI_Iprobe(src, TOKEN, MCW, &tokenFlag, &status); if(tokenFlag) { - MPI_Irecv(&tokenColor, 1, MPI_INT, src, TOKEN, MCW, &request); + MPI_Irecv(&tokenValue, 1, MPI_INT, src, TOKEN, MCW, &request); hasToken = true; - if(rank == 0 && tokenColor == WHITE) { + if(rank == 0 && tokenValue == SPECIAL) { int globalStop = -1; for(int i = 1; i < size; i++) { MPI_Send(&globalStop, 1, MPI_INT, i, JOB, MCW); } break; } - if(myColor == BLACK) { - tokenColor = BLACK; + if(myToken == GENERIC) { + tokenValue = GENERIC; } } } } } - - if(rank == 0) { //Print out the task information - int created, completed; +//Print info after run. + if(rank == 0) { + int created; + int completed; cout<<"Rank 0 created "<