Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ project(genericCommunicator)
cmake_minimum_required(VERSION 2.8.5)


###############################################################################
# CMAKE module path in utils/cmake/modules/
###############################################################################
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/utils/cmake/modules/" ${CMAKE_MODULE_PATH})

###############################################################################
# METIS
###############################################################################
find_package(METIS 5.1.0 REQUIRED)
include_directories(SYSTEM ${METIS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${METIS_LIBRARIES})

###############################################################################
# Boost
###############################################################################
Expand All @@ -10,7 +22,7 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})

################################################################################
# Find MPI
# MPI
################################################################################
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ GrayBat is licensed under the **GPLv3+**. Please refer to our [LICENSE.md](LICE
* Boost 1.57.0
* OpenMPI 1.8.0
* g++ 4.9.2
* Doxygen 1.8.8

* metis 5.1

##Compiling##

Expand Down
9 changes: 9 additions & 0 deletions include/Cave.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ namespace graybat {

}

/**
* @breif Returns the number of hosts
* of the current **graph**.
*
*/
unsigned nHosts(){
return getGraphContext(graph).size();
}


/**
* @brief Returns true if the *vertex* is hosted by the
Expand Down
102 changes: 102 additions & 0 deletions include/mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector> /* std::vector */
#include <assert.h> /* assert */
#include <stdlib.h> /* srand, rand */
#include <metis.h> /* idx_t, METIS_PartGraphKway */

/*******************************************************************************
*
Expand All @@ -16,6 +17,107 @@ namespace graybat {
namespace mapping {


/**
* Partitioning of the communication graph
* into k parts. k is set either to the
* number of peers that want to take
* part in communication or is given
* as an input parameter.
*
* @param nParts number of parts to partition
* @return set of vertices that belong "together"
*/
struct GraphPartition {

GraphPartition() : GraphPartition(0){

}

GraphPartition(unsigned nParts)
: nParts(nParts){

}

/**
* @Brief Translates the graph into the compressed row storage
* format (CSR) which can be parsed by Metis.
*
* @See http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_row_Storage_.28CRS_or_CSR.29
*
*/
template<typename T_Graph>
std::pair<std::vector<idx_t>, std::vector<idx_t> > toCompressedRowStorage(T_Graph &graph) {

typedef typename T_Graph::Vertex Vertex;
typedef typename T_Graph::Edge Edge;

unsigned i = 0;

std::vector<idx_t> xadj(1,i);
std::vector<idx_t> adjncy;


for(Vertex v : graph.getVertices()){
for(auto link : graph.getOutEdges(v)){
Vertex destVertex = link.first;
Edge destEdge = link.second;

adjncy.push_back(destVertex.id);
i++;

}
xadj.push_back(i);

}

return std::make_pair(xadj, adjncy);
}

template<typename T_Graph>
std::vector<typename T_Graph::Vertex> operator()(const unsigned processID, const unsigned processCount, T_Graph &graph){

typedef typename T_Graph::Vertex Vertex;
std::vector<Vertex> myVertices;
auto csr = toCompressedRowStorage(graph);

if(nParts == 0){
nParts = processCount;
}

if(nParts == 1){
return graph.getVertices();
}

idx_t nVertices = graph.getVertices().size();
idx_t nWeights = 1;
idx_t objval;
std::vector<idx_t> part(nVertices, 0);

METIS_PartGraphKway(&nVertices, &nWeights,
csr.first.data(), csr.second.data(),
NULL, NULL, NULL, &nParts, NULL,
NULL, NULL,
&objval,
part.data());


for(unsigned part_i = 0; part_i < part.size(); part_i++){
if(part[part_i] == (int)processID){
myVertices.push_back(graph.getVertices().at(part_i));
}

}

return myVertices;
}

private:
idx_t nParts;

};



/**
* Random distribution of vertices of the *graph* to the
* the peers. All peers need to set the same random *seed*.
Expand Down
2 changes: 1 addition & 1 deletion src/gol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int gol(const unsigned nCells, const unsigned nTimeSteps ) {
MyCave cave(graybat::pattern::GridDiagonal(height, width));

// Distribute vertices
cave.distribute(graybat::mapping::Consecutive());
cave.distribute(graybat::mapping::GraphPartition());

/***************************************************************************
* Run Simulation
Expand Down
33 changes: 33 additions & 0 deletions utils/cmake/modules/FindMETIS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Find the METIS includes and libraries
#
# ParMETIS is an MPI-based parallel library that implements a variety of algorithms for
# partitioning unstructured graphs, meshes, and for computing fill-reducing orderings of
# sparse matrices. It can be found at:
# http://www-users.cs.umn.edu/~karypis/metis/parmetis/index.html
#
# METIS_INCLUDE_DIR - where to find autopack.h
# METIS_LIBRARIES - List of fully qualified libraries to link against.
# METIS_FOUND - Do not attempt to use if "no" or undefined.

FIND_PATH(METIS_INCLUDE_DIR metis.h
/usr/local/include
/usr/include
)

FIND_LIBRARY(METIS_LIBRARY metis
/usr/local/lib
/usr/lib
)

FIND_LIBRARY(METIS_LIBRARY metis
/usr/local/lib
/usr/lib
)

IF(METIS_INCLUDE_DIR)
IF(METIS_LIBRARY)
SET( METIS_LIBRARIES ${METIS_LIBRARY} ${METIS_LIBRARY})
SET( METIS_FOUND "YES" )
ENDIF(METIS_LIBRARY)
ENDIF(METIS_INCLUDE_DIR)