made template function for flattening matrix
This commit is contained in:
@@ -13,7 +13,7 @@ set(HEADER_FILES
|
||||
set(SOURCE_FILES
|
||||
MakePermutationMatrix.cpp
|
||||
ReadFromFile.cpp
|
||||
CostMatrixGenerator.cpp CostMatrixGenerator.h)
|
||||
CostMatrixGenerator.cpp CostMatrixGenerator.h ParseMatrixForMPI.h)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_executable(HW10 ${HEADER_FILES} ${SOURCE_FILES} main.cpp)
|
||||
|
||||
33
HW10/ParseMatrixForMPI.h
Normal file
33
HW10/ParseMatrixForMPI.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by Brady Bodily on 3/29/20.
|
||||
//
|
||||
#include <vector>
|
||||
#ifndef HW10_PARSEMATRIXFORMPI_H
|
||||
#define HW10_PARSEMATRIXFORMPI_H
|
||||
namespace matrixTools
|
||||
{
|
||||
template <typename T>
|
||||
std::vector<std::vector<T>> UnflattenMatrix(std::vector<T> origianlVector, int rowSize, int columnSize)
|
||||
{
|
||||
std::vector<std::vector<T>> matrix(columnSize, std::vector<T>(rowSize, 0));
|
||||
for (int i = 0; i < columnSize; i++) {
|
||||
for (int j = 0; j < rowSize; j++) {
|
||||
matrix[i][j] = origianlVector[i + j];
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> FlattenMatrix(std::vector<std::vector<T>> matrix)
|
||||
{
|
||||
std::vector<T> rVector(matrix.size() * matrix[0].size(), 0);
|
||||
for (int i = 0; i < matrix.size(); i++) {
|
||||
for (int j = 0; j < matrix[0].size(); j++) {
|
||||
rVector[i + j] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
return rVector;
|
||||
}
|
||||
}
|
||||
#endif //HW10_PARSEMATRIXFORMPI_H
|
||||
@@ -1,2 +1,2 @@
|
||||
# Hashes of file build rules.
|
||||
c98ba7a6e4f716b81e2785f389cd31ac CMakeFiles/ClangFormat
|
||||
ec43966e55ea917fde3b84076c03b167 CMakeFiles/ClangFormat
|
||||
|
||||
@@ -54,7 +54,7 @@ CMAKE_BINARY_DIR = /Users/bradybodily/Repositories/CS5500_Parallel_Programming/H
|
||||
include CMakeFiles/ClangFormat.dir/progress.make
|
||||
|
||||
CMakeFiles/ClangFormat:
|
||||
/usr/local/bin/clang-format -i -style=file /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/MakePermutationMatrix.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/MakePermutationMatrix.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/main.cpp
|
||||
/usr/local/bin/clang-format -i -style=file /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/MakePermutationMatrix.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/MakePermutationMatrix.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.cpp /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ParseMatrixForMPI.h /Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/main.cpp
|
||||
|
||||
ClangFormat: CMakeFiles/ClangFormat
|
||||
ClangFormat: CMakeFiles/ClangFormat.dir/build.make
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h
|
||||
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.cpp
|
||||
CostMatrixGenerator.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h
|
||||
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h
|
||||
City.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h
|
||||
@@ -16,6 +20,10 @@ cmath
|
||||
vector
|
||||
-
|
||||
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ParseMatrixForMPI.h
|
||||
vector
|
||||
-
|
||||
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.h
|
||||
City.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h
|
||||
@@ -35,6 +43,8 @@ CostMatrixGenerator.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h
|
||||
ReadFromFile.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.h
|
||||
ParseMatrixForMPI.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ParseMatrixForMPI.h
|
||||
mpi.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/mpi.h
|
||||
iostream
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -16,6 +16,7 @@ CMakeFiles/HW10.dir/ReadFromFile.cpp.o
|
||||
CMakeFiles/HW10.dir/main.cpp.o
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/City.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/CostMatrixGenerator.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ParseMatrixForMPI.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.h
|
||||
/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/main.cpp
|
||||
/usr/local/Cellar/open-mpi/4.0.2/include/mpi.h
|
||||
|
||||
@@ -15,6 +15,7 @@ CMakeFiles/HW10.dir/ReadFromFile.cpp.o: ../ReadFromFile.h
|
||||
|
||||
CMakeFiles/HW10.dir/main.cpp.o: ../City.h
|
||||
CMakeFiles/HW10.dir/main.cpp.o: ../CostMatrixGenerator.h
|
||||
CMakeFiles/HW10.dir/main.cpp.o: ../ParseMatrixForMPI.h
|
||||
CMakeFiles/HW10.dir/main.cpp.o: ../ReadFromFile.h
|
||||
CMakeFiles/HW10.dir/main.cpp.o: ../main.cpp
|
||||
CMakeFiles/HW10.dir/main.cpp.o: /usr/local/Cellar/open-mpi/4.0.2/include/mpi.h
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -109,6 +109,9 @@
|
||||
<Unit filename="/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/MakePermutationMatrix.h">
|
||||
<Option target="HW10"/>
|
||||
</Unit>
|
||||
<Unit filename="/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ParseMatrixForMPI.h">
|
||||
<Option target="HW10"/>
|
||||
</Unit>
|
||||
<Unit filename="/Users/bradybodily/Repositories/CS5500_Parallel_Programming/HW10/ReadFromFile.cpp">
|
||||
<Option target="HW10"/>
|
||||
</Unit>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#import "CostMatrixGenerator.h"
|
||||
#include "CostMatrixGenerator.h"
|
||||
//#import "MakePermutationMatrix.h"
|
||||
#import "ReadFromFile.h"
|
||||
#import "mpi.h"
|
||||
#include "ReadFromFile.h"
|
||||
#include "ParseMatrixForMPI.h"
|
||||
#include "mpi.h"
|
||||
|
||||
#include <iostream>
|
||||
#define MCW MPI_COMM_WORLD
|
||||
@@ -14,6 +15,7 @@ int main(int argc, char* argv[])
|
||||
MPI_Comm_size(MCW, &size);
|
||||
std::vector<std::vector<double>> matrix;
|
||||
std::vector<City> cities;
|
||||
std::vector<double> flatMatrix;
|
||||
if (rank == 0) {
|
||||
std::cout << "Reading in file" << std::endl;
|
||||
cities = ReadFromFile::ReadFile("../input");
|
||||
@@ -26,6 +28,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
flatMatrix = matrixTools::FlattenMatrix(matrix);
|
||||
}
|
||||
MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||
if(rank){
|
||||
@@ -35,10 +38,9 @@ int main(int argc, char* argv[])
|
||||
matrix[i].resize(citiesSize);
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < citiesSize; i++) {
|
||||
MPI_Bcast(&(matrix[0][i]), citiesSize, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||
}
|
||||
MPI_Bcast(&flatMatrix, flatMatrix.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||
if(rank){
|
||||
matrix = matrixTools::UnflattenMatrix(flatMatrix, citiesSize, citiesSize);
|
||||
std::cout << "Process "<< rank << " has value " << citiesSize << " as size of city" << std::endl;
|
||||
for(int i = 0; i < citiesSize; i++) {
|
||||
for (int j = 0; j < citiesSize; j++) {
|
||||
|
||||
Reference in New Issue
Block a user