├── init.sh ├── blosc_filter ├── Makefile ├── blosc_filter.h ├── blosc_plugin.h └── blosc_plugin.c ├── karate.graph ├── DefineStructure ├── color_comm.h ├── RngStream.h ├── coloring.h ├── basic_util.h ├── sync_comm.h ├── input_output.h ├── basic_comm.h ├── dataStructureHeap.h ├── coloringUtils.h ├── utilityClusteringFunctions.h └── defs.h ├── README_cmake_build ├── FullSyncOptimization ├── CMakeLists.txt └── fullSyncUtility.cpp ├── InputsOutput ├── CMakeLists.txt ├── writeBinary.cpp ├── loadBinary.cpp ├── writeSimple.cpp ├── loadDimacs.cpp └── writeMatrixMarket.cpp ├── Coloring ├── CMakeLists.txt └── vBase.cpp ├── Utility ├── CMakeLists.txt └── utilityDataStructures.cpp ├── BasicCommunitiesDetection └── CMakeLists.txt ├── LICENSE ├── run1.sh ├── gpu_graph ├── CMakeLists.txt ├── hashitem.h ├── devconstants.h ├── commonconstants.h ├── hostconstants.h ├── computeTime.cu ├── graphGPU.h ├── openaddressing.h ├── assignGraph.cu ├── computeModularity.cu ├── graphHOST.h ├── graphHOST.cpp ├── communityGPU.cu └── preprocessing.cu ├── convertSNAPGroundTruthInformation.cpp ├── Makefile.old ├── driverForClusterComparison.cpp ├── reserver ├── convertFileToEdgeList.cpp ├── convertFileToBinary.cpp ├── convert └── convertSnapFileToBinary.cpp ├── Makefile-HDF5 ├── convertFileToBinary.cpp ├── CMakeLists.txt ├── driverForPartitioningWithMetis.cpp ├── bColoring ├── cBase.cpp ├── bBase.cpp └── initialColoringLU.cpp ├── driverForMatrixReorderingRcm.cpp ├── README.txt ├── driverForColoring.cpp └── driverForMatrixReorderingND.cpp /init.sh: -------------------------------------------------------------------------------- 1 | for i in {2..7}; 2 | do 3 | ./run$i.sh 4 | done -------------------------------------------------------------------------------- /blosc_filter/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | HDF_INC=$(HDF5_ROOT)/include 4 | CFLAGS = -I$(HDF_INC) -I$(BLOSC_ROOT)/include -shared -fPIC 5 | 6 | TARGET = blosc_filter.so blosc_plugin.so 7 | 8 | all: $(TARGET) 9 | 10 | $(TARGET) : %.so: %.c 11 | $(CC) $(CFLAGS) -o $@ $^ 12 | 13 | clean: 14 | rm -f *~ $(OBJFILES) $(TARGET) 15 | -------------------------------------------------------------------------------- /karate.graph: -------------------------------------------------------------------------------- 1 | 34 78 0 2 | 2 3 4 5 6 7 8 9 11 12 13 14 18 20 22 32 3 | 1 3 4 8 14 18 20 22 31 4 | 1 2 4 8 9 10 14 28 29 33 5 | 1 2 3 8 13 14 6 | 1 7 11 7 | 1 7 11 17 8 | 1 5 6 17 9 | 1 2 3 4 10 | 1 3 31 33 34 11 | 3 34 12 | 1 5 6 13 | 1 14 | 1 4 15 | 1 2 3 4 34 16 | 33 34 17 | 33 34 18 | 6 7 19 | 1 2 20 | 33 34 21 | 1 2 34 22 | 33 34 23 | 1 2 24 | 33 34 25 | 26 28 30 33 34 26 | 26 28 32 27 | 24 25 32 28 | 30 34 29 | 3 24 25 34 30 | 3 32 34 31 | 24 27 33 34 32 | 2 9 33 34 33 | 1 25 26 29 33 34 34 | 3 9 15 16 19 21 23 24 30 31 32 34 35 | 9 10 14 15 16 19 20 21 23 24 27 28 29 30 31 32 33 36 | -------------------------------------------------------------------------------- /blosc_filter/blosc_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef FILTER_BLOSC_H 2 | #define FILTER_BLOSC_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "blosc.h" 9 | 10 | /* Filter revision number, starting at 1 */ 11 | /* #define FILTER_BLOSC_VERSION 1 */ 12 | #define FILTER_BLOSC_VERSION 2 /* multiple compressors since Blosc 1.3 */ 13 | 14 | /* Filter ID registered with the HDF Group */ 15 | #define FILTER_BLOSC 32001 16 | 17 | /* Registers the filter with the HDF5 library. */ 18 | #if defined(_MSC_VER) 19 | __declspec(dllexport) 20 | #endif /* defined(_MSC_VER) */ 21 | int register_blosc(char **version, char **date); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /DefineStructure/color_comm.h: -------------------------------------------------------------------------------- 1 | #ifndef __color_comm__ 2 | #define __color_comm__ 3 | 4 | #include "basic_comm.h" 5 | #include "coloring.h" 6 | 7 | void runMultiPhaseColoring(graph *G, long *C_orig, int coloring, int numColors, int replaceMap, long minGraphSize, 8 | double threshold, double C_threshold, int numThreads, int threadsOpt); 9 | 10 | double algoLouvainWithDistOneColoring(graph* G, long *C, int nThreads, int* color, 11 | int numColor, double Lower, double thresh, double *totTime, int *numItr); 12 | 13 | double algoLouvainWithDistOneColoringNoMap(graph* G, long *C, int nThreads, int* color, 14 | int numColor, double Lower, double thresh, double *totTime, int *numItr); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /README_cmake_build: -------------------------------------------------------------------------------- 1 | On Constance cluster of PNNL following compiler 2 | combinations work ok: 3 | 4 | $ module load gcc/7.1.0 5 | $ module load cuda/9.2.148 6 | $ module load cmake/3.8.2 7 | 8 | In the base level CMakeLists.txt 9 | set the DEFINE_RUNONGPU option to ON 10 | as under: 11 | 12 | option( DEFINE_RUNONGPU "Use of GPU" ON) 13 | 14 | 15 | $ cd ~/grappolo-09-2016 16 | $ mkdir build install 17 | $ cd build 18 | $ cmake ../ -DCMAKE_INSTALL_PREFIX=~/grappolo-09-2016/install 19 | $ make -j4 20 | $ make install 21 | 22 | RUN the gpu_graph executable within a directory 23 | that contains file 'fewprimes.txt' 24 | 25 | command to run the gpu_graph executable 26 | 27 | $ ./install/bin/gpu_graph -p 100 -f 1 ..//af_shell9.mtx 28 | -------------------------------------------------------------------------------- /blosc_filter/blosc_plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dynamically loaded filter plugin for HDF5 blosc filter. 3 | * 4 | * Author: Kiyoshi Masui 5 | * Created: 2014 6 | * 7 | * 8 | * Header file 9 | * ----------- 10 | * 11 | * This provides dynamically loaded HDF5 filter functionality (introduced 12 | * in HDF5-1.8.11, May 2013) to the blosc HDF5 filter. 13 | * 14 | * Usage: compile as a shared library and install either to the default 15 | * search location for HDF5 filter plugins (on Linux 16 | * /usr/local/hdf5/lib/plugin) or to a location pointed to by the 17 | * HDF5_PLUGIN_PATH environment variable. 18 | * 19 | */ 20 | 21 | 22 | #ifndef PLUGIN_BLOSC_H 23 | #define PLUGIN_BLOSC_H 24 | 25 | #include "H5PLextern.h" 26 | 27 | 28 | H5PL_type_t H5PLget_plugin_type(void); 29 | 30 | 31 | const void* H5PLget_plugin_info(void); 32 | 33 | 34 | #endif // PLUGIN_BLOSC_H 35 | 36 | 37 | -------------------------------------------------------------------------------- /FullSyncOptimization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( IO_HEADERS 4 | ${CMAKE_SOURCE_DIR}/DefineStructure 5 | ) 6 | 7 | set( FSFOLDER_SRC 8 | ${CMAKE_SOURCE_DIR}/${FSFOLDER}/fullSyncUtility.cpp 9 | ${CMAKE_SOURCE_DIR}/${FSFOLDER}/parallelLouvainMethodEarlyTerminate.cpp 10 | ${CMAKE_SOURCE_DIR}/${FSFOLDER}/parallelLouvainMethodFullSync.cpp 11 | ${CMAKE_SOURCE_DIR}/${FSFOLDER}/parallelLouvainMethodFullSyncEarly.cpp 12 | ${CMAKE_SOURCE_DIR}/${FSFOLDER}/runMultiPhaseSyncType.cpp 13 | ) 14 | 15 | add_library( full_syn_opt STATIC 16 | ${FSFOLDER_SRC} 17 | ) 18 | 19 | target_include_directories( full_syn_opt PUBLIC ${IO_HEADERS} ) 20 | 21 | target_link_libraries( full_syn_opt ) 22 | 23 | install( TARGETS 24 | full_syn_opt 25 | DESTINATION lib 26 | ) 27 | 28 | install( FILES 29 | ${IO_HEADERS}/defs.h 30 | ${IO_HEADERS}/utilityClusteringFunctions.h 31 | ${IO_HEADERS}/sync_comm.h 32 | DESTINATION include 33 | ) 34 | 35 | -------------------------------------------------------------------------------- /blosc_filter/blosc_plugin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Dynamically loaded filter plugin for HDF5 blosc filter. 3 | * 4 | * Author: Kiyoshi Masui 5 | * Created: 2014 6 | * 7 | */ 8 | 9 | 10 | #include 11 | 12 | 13 | #define H5Z_class_t_vers 2 14 | 15 | #include "blosc_plugin.h" 16 | #include "blosc_filter.h" 17 | 18 | 19 | // Prototypes for filter function in blosc_filter.c. 20 | size_t blosc_filter(unsigned flags, size_t cd_nelmts, 21 | const unsigned cd_values[], size_t nbytes, 22 | size_t *buf_size, void **buf); 23 | 24 | herr_t blosc_set_local(hid_t dcpl, hid_t type, hid_t space); 25 | 26 | 27 | H5Z_class_t blosc_H5Filter[1] = {{ 28 | H5Z_CLASS_T_VERS, 29 | (H5Z_filter_t)(FILTER_BLOSC), 30 | 1, 1, 31 | "blosc", 32 | NULL, 33 | (H5Z_set_local_func_t)(blosc_set_local), 34 | (H5Z_func_t)(blosc_filter) 35 | }}; 36 | 37 | 38 | H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;} 39 | 40 | 41 | const void* H5PLget_plugin_info(void) {return blosc_H5Filter;} 42 | 43 | -------------------------------------------------------------------------------- /InputsOutput/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( IO_HEADERS 4 | ${CMAKE_SOURCE_DIR}/DefineStructure 5 | ) 6 | 7 | set( IOFOLDER_SRC 8 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadBinary.cpp 9 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadDimacs.cpp 10 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadEdgeList.cpp 11 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadMatrixMarket.cpp 12 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadMetis.cpp 13 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadPajekFormat.cpp 14 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/loadSNAP.cpp 15 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/parseInputParameters.cpp 16 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/writeBinary.cpp 17 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/writeMatrixMarket.cpp 18 | ${CMAKE_SOURCE_DIR}/${IOFOLDER}/writeSimple.cpp 19 | ) 20 | 21 | add_library( inout STATIC 22 | ${IOFOLDER_SRC} 23 | ) 24 | 25 | target_include_directories(inout PUBLIC ${IO_HEADERS} ) 26 | 27 | target_link_libraries( inout ) 28 | 29 | install( TARGETS 30 | inout 31 | DESTINATION lib 32 | ) 33 | 34 | install( FILES 35 | ${IO_HEADERS}/input_output.h 36 | DESTINATION include 37 | ) 38 | 39 | -------------------------------------------------------------------------------- /DefineStructure/RngStream.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef RNGSTREAM_H 4 | #define RNGSTREAM_H 5 | 6 | #include 7 | 8 | class RngStream 9 | { 10 | public: 11 | 12 | RngStream (const char *name = ""); 13 | 14 | 15 | static bool SetPackageSeed (const unsigned long seed[6]); 16 | 17 | 18 | void ResetStartStream (); 19 | 20 | 21 | void ResetStartSubstream (); 22 | 23 | 24 | void ResetNextSubstream (); 25 | 26 | 27 | void SetAntithetic (bool a); 28 | 29 | 30 | void IncreasedPrecis (bool incp); 31 | 32 | 33 | bool SetSeed (const unsigned long seed[6]); 34 | 35 | 36 | void AdvanceState (long e, long c); 37 | 38 | 39 | void GetState (unsigned long seed[6]) const; 40 | 41 | 42 | void WriteState () const; 43 | 44 | 45 | void WriteStateFull () const; 46 | 47 | 48 | double RandU01 (); 49 | 50 | 51 | int RandInt (int i, int j); 52 | 53 | 54 | 55 | private: 56 | 57 | double Cg[6], Bg[6], Ig[6]; 58 | 59 | 60 | bool anti, incPrec; 61 | 62 | 63 | std::string name; 64 | 65 | 66 | static double nextSeed[6]; 67 | 68 | 69 | double U01 (); 70 | 71 | 72 | double U01d (); 73 | 74 | 75 | }; 76 | 77 | #endif 78 | 79 | 80 | -------------------------------------------------------------------------------- /DefineStructure/coloring.h: -------------------------------------------------------------------------------- 1 | #ifndef __coloring__ 2 | #define __coloring__ 3 | 4 | #include "basic_util.h" 5 | #include "coloringUtils.h" 6 | 7 | // In coloringDistanceOne.cpp 8 | int algoDistanceOneVertexColoringOpt(graph *G, int *vtxColor, int nThreads, double *totTime); 9 | int algoDistanceOneVertexColoring(graph *G, int *vtxColor, int nThreads, double *totTime); 10 | 11 | // In ColoringMultiHasMaxMin.cpp 12 | int algoColoringMultiHashMaxMin(graph *G, int *vtxColor, int nThreads, double *totTime, int nHash, int nItrs); 13 | 14 | // In vBase.cpp 15 | int vBaseRedistribution(graph* G, int* vtxColor, int ncolors, int type); 16 | 17 | // In equtiableColoringDistanceOne.cpp 18 | void buildColorSize(long NVer, int *vtxColor, int numColors, long *colorSize); 19 | void computeVariance(long NVer, int numColors, long *colorSize); 20 | 21 | void equitableDistanceOneColorBased(graph *G, int *vtxColor, int numColors, long *colorSize, 22 | int nThreads, double *totTime, int type); 23 | 24 | int algoColoringMultiHashMaxMin(graph *G, int *vtxColor, int nThreads, double *totTime, int nHash, int nItrs); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Coloring/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( IO_HEADERS 4 | ${CMAKE_SOURCE_DIR}/DefineStructure 5 | ) 6 | 7 | set( CLFOLDER_SRC 8 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/coloringDistanceOne.cpp 9 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/coloringMultiHashMaxMin.cpp 10 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/coloringUtils.cpp 11 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/equitableColoringDistanceOne.cpp 12 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/parallelLouvainWithColoring.cpp 13 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/parallelLouvainWithColoringNoMap.cpp 14 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/runMultiPhaseColoring.cpp 15 | ${CMAKE_SOURCE_DIR}/${CLFOLDER}/vBase.cpp 16 | ) 17 | 18 | add_library( coloring STATIC 19 | ${CLFOLDER_SRC} 20 | ) 21 | 22 | target_include_directories( coloring PUBLIC ${IO_HEADERS} ) 23 | 24 | target_link_libraries( coloring ) 25 | 26 | install( TARGETS 27 | coloring 28 | DESTINATION lib 29 | ) 30 | 31 | install( FILES 32 | ${IO_HEADERS}/defs.h 33 | ${IO_HEADERS}/coloring.h 34 | ${IO_HEADERS}/coloringUtils.h 35 | ${IO_HEADERS}/utilityClusteringFunctions.h 36 | ${IO_HEADERS}/color_comm.h 37 | ${IO_HEADERS}/basic_comm.h 38 | DESTINATION include 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /Utility/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( IO_HEADERS 4 | ${CMAKE_SOURCE_DIR}/DefineStructure 5 | ) 6 | 7 | set( UTFOLDER_SRC 8 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/buildNextPhase.cpp 9 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/reverseCuthillMcKee.cpp 10 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/RngStream.cpp 11 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/utilityClusterComparisonMetrics.cpp 12 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/utilityClusteringFunctions.cpp 13 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/utilityDataStructures.cpp 14 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/utilityFunctions.cpp 15 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/utilitySparsificationFunctions.cpp 16 | ${CMAKE_SOURCE_DIR}/${UTFOLDER}/vertexFollowing.cpp 17 | ) 18 | 19 | add_library( util STATIC 20 | ${UTFOLDER_SRC} 21 | ) 22 | 23 | target_include_directories( util PUBLIC ${IO_HEADERS} ) 24 | 25 | target_link_libraries( util ) 26 | 27 | install( TARGETS 28 | util 29 | DESTINATION lib 30 | ) 31 | 32 | install( FILES 33 | ${IO_HEADERS}/defs.h 34 | ${IO_HEADERS}/basic_util.h 35 | ${IO_HEADERS}/utilityClusteringFunctions.h 36 | ${IO_HEADERS}/RngStream.h 37 | ${IO_HEADERS}/basic_comm.h 38 | DESTINATION include 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /DefineStructure/basic_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILITLY__ 2 | #define __UTILITLY__ 3 | 4 | // Define in buildNextPhase.cpp 5 | long renumberClustersContiguously(long *C, long size); 6 | double buildNextLevelGraphOpt(graph *Gin, graph *Gout, long *C, long numUniqueClusters, int nThreads); 7 | void buildNextLevelGraph(graph *Gin, graph *Gout, long *C, long numUniqueClusters); 8 | long buildCommunityBasedOnVoltages(graph *G, long *Volts, long *C, long *Cvolts); 9 | void segregateEdgesBasedOnVoltages(graph *G, long *Volts); 10 | inline void Visit(long v, long myCommunity, short *Visited, long *Volts, 11 | long* vtxPtr, edge* vtxInd, long *C); 12 | 13 | // Define in vertexFollowing.cpp 14 | long vertexFollowing(graph *G, long *C); 15 | double buildNewGraphVF(graph *Gin, graph *Gout, long *C, long numUniqueClusters); 16 | 17 | // Define in utilityFunctions.cpp 18 | double computeGiniCoefficient(long *colorSize, int numColors); 19 | void generateRandomNumbers(double *RandVec, long size); 20 | void displayGraph(graph *G); 21 | void duplicateGivenGraph(graph *Gin, graph *Gout); 22 | void displayGraphEdgeList(graph *G); 23 | void writeEdgeListToFile(graph *G, FILE* out); 24 | void displayGraphCharacteristics(graph *G); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /DefineStructure/sync_comm.h: -------------------------------------------------------------------------------- 1 | #ifndef __sync_comm__ 2 | #define __sync_comm__ 3 | 4 | #include "basic_util.h" 5 | #include "utilityClusteringFunctions.h" 6 | 7 | void runMultiPhaseSyncType(graph *G, long *C_orig, int syncType, long minGraphSize, 8 | double threshold, double C_threshold, int numThreads, int threadsOpt); 9 | 10 | double parallelLouvainMethodFullSyncEarly(graph *G, long *C, int nThreads, double Lower, 11 | double thresh, double *totTime, int *numItr,int ytype, int freedom); 12 | 13 | double parallelLouvainMethodFullSync(graph *G, long *C, int nThreads, double Lower, 14 | double thresh, double *totTime, int *numItr,int ytype, int freedom); 15 | 16 | double parallelLouvianMethodEarlyTerminate(graph *G, long *C, int nThreads, double Lower, 17 | double thresh, double *totTime, int *numItr); 18 | 19 | // Define in fullSyncUtility.cpp 20 | double buildAndLockLocalMapCounter(long v, mapElement* clusterLocalMap, long* vtxPtr, edge* vtxInd, 21 | long* currCommAss, long &numUniqueClusters, omp_lock_t* vlocks, omp_lock_t* clocks, int ytype, double& eix, int freedom); 22 | 23 | void maxAndFree(long v, mapElement* clusterLocalMap, long* vtxPtr, edge* vtxInd, double selfLoop, Comm* cInfo, long* CA, 24 | double constant, long numUniqueClusters, omp_lock_t* vlocks, omp_lock_t* clocks, int ytype, double eix, double* vDegree); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /InputsOutput/writeBinary.cpp: -------------------------------------------------------------------------------- 1 | #include "input_output.h" 2 | void writeGraphBinaryFormatNew(graph* G, char *filename, long weighted) { 3 | //Get the iterators for the graph: 4 | long NVer = G->numVertices; 5 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 6 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 7 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 8 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 9 | printf("Writing graph in a simple edgelist format - each edge stored TWICE.\n"); 10 | 11 | ofstream ofs; 12 | ofs.open(filename, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); 13 | if (!ofs) { 14 | std::cerr << "Error opening output file: " << filename << std::endl; 15 | exit(EXIT_FAILURE); 16 | } 17 | 18 | //First Line: #Vertices #Edges 19 | ofs.write(reinterpret_cast(&NVer), sizeof(NVer)); 20 | ofs.write(reinterpret_cast(&NEdge), sizeof(NEdge)); 21 | ofs.write(reinterpret_cast(&weighted),sizeof(weighted)); 22 | 23 | //Write all the edges (each edge stored twice): 24 | ofs.write(reinterpret_cast(verPtr), (NVer+1)*sizeof(long)); 25 | ofs.write(reinterpret_cast(verInd), (2*NEdge)*sizeof(edge)); 26 | 27 | ofs.close(); 28 | printf("Graph has been stored in file: %s\n",filename); 29 | }//End of writeGraphBinaryFormatTwice() -------------------------------------------------------------------------------- /BasicCommunitiesDetection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( IO_HEADERS 4 | ${CMAKE_SOURCE_DIR}/DefineStructure 5 | ) 6 | 7 | set( COFOLDER_SRC 8 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodApprox-2.cpp 9 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodApprox.cpp 10 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethod.cpp 11 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodFastTrackResistance.cpp 12 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodNoMap.cpp 13 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodNoMapFastTrackResistance.cpp 14 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodScale.cpp 15 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/parallelLouvainMethodScaleFastTrackResistance.cpp 16 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/runMultiPhaseBasicApprox.cpp 17 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/runMultiPhaseBasic.cpp 18 | ${CMAKE_SOURCE_DIR}/${COFOLDER}/runMultiPhaseBasicFastTrackResistance.cpp 19 | ) 20 | 21 | 22 | add_library( basic_cd 23 | ${COFOLDER_SRC} 24 | ) 25 | 26 | target_include_directories(basic_cd PUBLIC ${IO_HEADERS} ) 27 | 28 | target_link_libraries( basic_cd ) 29 | 30 | install( TARGETS 31 | basic_cd 32 | DESTINATION lib 33 | ) 34 | 35 | install( FILES 36 | ${IO_HEADERS}/defs.h 37 | ${IO_HEADERS}/utilityClusteringFunctions.h 38 | ${IO_HEADERS}/basic_comm.h 39 | ${IO_HEADERS}/basic_util.h 40 | DESTINATION include 41 | ) 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2014, Battelle Memorial Institute 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /InputsOutput/loadBinary.cpp: -------------------------------------------------------------------------------- 1 | #include "input_output.h" 2 | #include "defs.h" 3 | #include "sstream" 4 | #include "utilityStringTokenizer.hpp" 5 | 6 | void parse_EdgeListBinaryNew(graph * G, char *fileName) { 7 | printf("Parsing a file in binary format...\n"); 8 | printf("WARNING: Assumes that the graph is undirected -- every edge is stored twice.\n"); 9 | int nthreads = 0; 10 | 11 | #pragma omp parallel 12 | { 13 | nthreads = omp_get_num_threads(); 14 | } 15 | 16 | double time1, time2; 17 | 18 | std::ifstream ifs; 19 | ifs.open(fileName, std::ifstream::in | std::ifstream::binary); 20 | if (!ifs) { 21 | std::cerr << "Error opening binary format file: " << fileName << std::endl; 22 | exit(EXIT_FAILURE); 23 | } 24 | 25 | long NV, NE, weighted; 26 | //Parse line-1: #Vertices #Edges 27 | ifs.read(reinterpret_cast(&NV), sizeof(NV)); 28 | ifs.read(reinterpret_cast(&NE), sizeof(NE)); 29 | ifs.read(reinterpret_cast(&weighted), sizeof(weighted)); 30 | 31 | long* verPtrRaw = (long*) malloc( (NV+1)*sizeof(long)); assert(verPtrRaw != 0); 32 | edge* edgeListRaw = (edge*) malloc(2*NE*sizeof(edge)); assert(edgeListRaw != 0); 33 | 34 | ifs.read(reinterpret_cast(verPtrRaw), sizeof(long) * (NV+1)); 35 | ifs.read(reinterpret_cast(edgeListRaw), sizeof(edge) * (2*NE)); 36 | 37 | ifs.close(); //Close the file 38 | 39 | G->sVertices = NV; 40 | G->numVertices = NV; 41 | G->numEdges = NE; 42 | G->edgeListPtrs = verPtrRaw; 43 | G->edgeList = edgeListRaw; 44 | 45 | //Clean up 46 | 47 | //displayGraph(G); 48 | }//End of parse_Dimacs9FormatDirectedNewD() 49 | -------------------------------------------------------------------------------- /run1.sh: -------------------------------------------------------------------------------- 1 | cp ./datasets/karate.graph ./datasets/karateApprox100.graph 2 | cp ./datasets/karate.graph ./datasets/karateApprox90.graph 3 | cp ./datasets/karate.graph ./datasets/karateApprox80.graph 4 | cp ./datasets/karate.graph ./datasets/karateApprox70.graph 5 | cp ./datasets/karate.graph ./datasets/karateMap.graph 6 | cp ./datasets/karate.graph ./datasets/karateNoMap.graph 7 | for i in {1..10}; 8 | do 9 | #echo $i 10 | 11 | #numactl --interleave=all 12 | 13 | ./bin/driverForGraphClusteringApprox -p 100 -f 5 ./datasets/karateApprox100.graph -b 0 -o >> karate.graph_clustInfoApprox100.out$i 14 | mv ./datasets/karateApprox100.graph_clustInfo ./results/karateApprox100.nocolor.rand.out$i 15 | ./bin/driverForGraphClusteringApprox -p 90 -f 5 ./datasets/karateApprox90.graph -b 0 -o >> karate.graph_clustInfoApprox90.out$i 16 | mv ./datasets/karateApprox90.graph_clustInfo ./results/karateApprox90.nocolor.rand.out$i 17 | ./bin/driverForGraphClusteringApprox -p 80 -f 5 ./datasets/karateApprox80.graph -b 0 -o >> karate.graph_clustInfoApprox80.out$i 18 | mv ./datasets/karateApprox80.graph_clustInfo ./results/karateApprox80.nocolor.rand.out$i 19 | ./bin/driverForGraphClusteringApprox -p 70 -f 5 ./datasets/karateApprox70.graph -b 0 -o >> karate.graph_clustInfoApprox70.out$i 20 | mv ./datasets/karateApprox70.graph_clustInfo ./results/karateApprox70.nocolor.rand.out$i 21 | 22 | done 23 | ./bin/driverForGraphClustering -f 5 ./datasets/karateMap.graph -b 0 -o >> karate.graph_clustInfoMap.out 24 | mv ./datasets/karateMap.graph_clustInfo ./results/karateMap.nocolor.rand.out1 25 | ./bin/driverForGraphClustering -f 5 ./datasets/karateNoMap.graph -b 1 -o >> karate.graph_clustInfoNoMap.out 26 | mv ./datasets/karateNoMap.graph_clustInfo ./results/karateNoMap.nocolor.rand.out1 -------------------------------------------------------------------------------- /gpu_graph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # grappolo 2 | 3 | set( GPU_HEADERS 4 | ${CMAKE_SOURCE_DIR}/gpu_graph 5 | ) 6 | 7 | set( GPUFOLDER_SRC 8 | #${CMAKE_SOURCE_DIR}/${GPUFOLDER}/gpu_main.cpp 9 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/graphHOST.cpp 10 | 11 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/aggregateCommunity.cu 12 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/assignGraph.cu 13 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/binWiseGaussSeidel.cu 14 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/communityGPU.cu 15 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/computeModularity.cu 16 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/computeTime.cu 17 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/coreutility.cu 18 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/gatherInformation.cu 19 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/graphGPU.cu 20 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/independentKernels.cu 21 | ${CMAKE_SOURCE_DIR}/${GPUFOLDER}/preprocessing.cu 22 | ) 23 | 24 | #CUDA_ADD_LIBRARY( gpu_graph 25 | # SHARED 26 | # ${GPUFOLDER_SRC} 27 | # OPTIONS -arch sm_35 28 | #) 29 | 30 | CUDA_ADD_EXECUTABLE( gpu_graph 31 | gpu_main.cpp 32 | ${GPUFOLDER_SRC} 33 | #OPTIONS -arch sm_35 34 | OPTIONS -arch sm_37 35 | DEBUG -g -G 36 | ) 37 | 38 | target_include_directories( gpu_graph 39 | PUBLIC 40 | ${GPU_HEADERS} 41 | ${IO_HEADERS} 42 | ) 43 | 44 | target_link_libraries( gpu_graph 45 | inout 46 | util 47 | ${CUDA_LIBRARIES} 48 | ) 49 | 50 | install( TARGETS 51 | gpu_graph 52 | #DESTINATION lib 53 | DESTINATION bin 54 | ) 55 | 56 | install( FILES 57 | ${GPU_HEADERS}/commonconstants.h 58 | ${GPU_HEADERS}/communityGPU.h 59 | ${GPU_HEADERS}/devconstants.h 60 | ${GPU_HEADERS}/graphGPU.h 61 | ${GPU_HEADERS}/graphHOST.h 62 | ${GPU_HEADERS}/hashitem.h 63 | ${GPU_HEADERS}/hostconstants.h 64 | ${GPU_HEADERS}/myutility.h 65 | ${GPU_HEADERS}/openaddressing.h 66 | DESTINATION include 67 | ) 68 | 69 | -------------------------------------------------------------------------------- /DefineStructure/input_output.h: -------------------------------------------------------------------------------- 1 | #ifndef __input__output 2 | #define __input__output 3 | #include "defs.h" 4 | 5 | long removeEdges(long NV, long NE, edge *edgeList); //Remove duplicates 6 | void SortEdgesUndirected(long NV, long NE, edge *list1, edge *list2, long *ptrs); 7 | 8 | void loadMetisFileFormat(graph *G, const char* filename); //Metis (DIMACS#10) 9 | bool parse_MatrixMarket(graph * G, char *fileName); //Matrix-Market 10 | void parse_MatrixMarket_Sym_AsGraph(graph * G, char *fileName); 11 | 12 | void parse_DirectedEdgeList(dGraph * G, char *fileName); //Directed graph 13 | void parse_UndirectedEdgeListWeighted(graph * G, char *fileName); // for John F's graphs 14 | void parse_UndirectedEdgeList(graph * G, char *fileName); 15 | void parse_EdgeListBinaryNew(graph * G, char *fileName); 16 | void parse_PajekFormatUndirected(graph* G, char* fileName); 17 | void parse_PajekFormat(graph* G, char* fileName); 18 | void parse_Dimacs9FormatDirectedNewD(graph* G, char* fileName); 19 | void parse_SNAP(graph * G, char *fileName); 20 | void parse_SNAP_GroundTruthCommunities(char *fileVertexMap, char *fileGroundTruth); 21 | void parse_UndirectedEdgeListFromJason(graph * G, char *fileName); //Data from Jason 22 | void parse_UndirectedEdgeListDarpaHive(graph * G, char *fileName); //DARPA-HIVE Challenge 23 | void parse_EdgeListFromGorder(graph * G, char *fileName); //Gorder files 24 | 25 | void writeGraphBinaryFormatNew(graph* G, char *filename, long weighted); 26 | void writeGraphMetisSimpleFormat(graph* G, char *filename); 27 | void writeGraphMatrixMarketFormatSymmetric(graph* G, char *filename); 28 | 29 | void writeGraphPajekFormat(graph* G, char *filename); //Pajek 30 | void writeGraphPajekFormatWithCommunityInfo(graph* G, char *filename, long *C); //Pajek+Community 31 | 32 | void writeGraphMatrixMarketFormatSymmetricReordered(graph* G, char *filename, long *old2NewMap); 33 | void writeGraphMatrixMarketFormatBipartiteReordered(graph* G, char *filename, long *old2NewMap); 34 | 35 | void parse_EdgeListCompressedHDF5(graph * G, char *fileName); 36 | void parse_EdgeListCompressedHDF5NoDuplicates(graph * G, char *fileName); 37 | 38 | using namespace std; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /gpu_graph/hashitem.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | /* 42 | * File: hashitem.h 43 | * Author: Naim 44 | * 45 | * Created on January 12, 2016, 12:53 PM 46 | */ 47 | 48 | #ifndef HASHITEM_H 49 | #define HASHITEM_H 50 | 51 | struct HashItem { 52 | int cId; 53 | float gravity; 54 | }; 55 | #endif /* HASHITEM_H */ 56 | 57 | -------------------------------------------------------------------------------- /gpu_graph/devconstants.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | /* 43 | * File: devconstants.h 44 | * Author: Naim 45 | * 46 | * Created on January 18, 2016, 5:28 PM 47 | */ 48 | 49 | #ifndef DEVCONSTANTS_H 50 | #define DEVCONSTANTS_H 51 | 52 | #define PHY_WRP_SZ 32 53 | #define FLAG_FREE 0 54 | 55 | #endif /* DEVCONSTANTS_H */ 56 | 57 | -------------------------------------------------------------------------------- /gpu_graph/commonconstants.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef COMMONCONSTANTS_H 43 | #define COMMONCONSTANTS_H 44 | 45 | #include"devconstants.h" 46 | 47 | #define CHUNK_PER_WARP 32 48 | #define NR_THREAD_PER_BLOCK 128 49 | 50 | #define WEIGHTED 0 51 | #define UNWEIGHTED 1 52 | 53 | #define PRINTALL 0 54 | 55 | #endif /* COMMONCONSTANTS_H */ 56 | 57 | -------------------------------------------------------------------------------- /gpu_graph/hostconstants.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef HOSTCONSTANTS_H 43 | #define HOSTCONSTANTS_H 44 | 45 | 46 | #define SHARED_TABLE_SIZE 479 // Must be a Prime 47 | #define WARP_TABLE_SIZE_1 127 // Must be a Prime 48 | 49 | #define CAPACITY_FACTOR_NUMERATOR 2 50 | #define CAPACITY_FACTOR_DENOMINATOR 3 51 | #define HALF_WARP 16 52 | #define QUARTER_WARP 8 53 | #endif /* HOSTCONSTANTS_H */ 54 | -------------------------------------------------------------------------------- /gpu_graph/computeTime.cu: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include 43 | #include 44 | #include "communityGPU.h" 45 | 46 | void report_time(cudaEvent_t start, cudaEvent_t stop, std::string moduleName) { 47 | /* 48 | cudaEventRecord(stop, 0); 49 | cudaEventSynchronize(stop); 50 | float milliseconds = 0; 51 | cudaEventElapsedTime(&milliseconds, start, stop); 52 | //if(moduleName.compare("FilterCopy&M")) 53 | std::cout << moduleName << " (kernel): " << milliseconds << std::endl; 54 | */ 55 | } 56 | 57 | -------------------------------------------------------------------------------- /DefineStructure/basic_comm.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASIC__COMM__ 2 | #define __BASIC__COMM__ 3 | 4 | // Define in louvainMultiPhaseRun.cpp 5 | void runMultiPhaseBasic(graph *G, long *C_orig, int basicOpt, long minGraphSize, 6 | double threshold, double C_threshold, int numThreads, int threadsOpt); 7 | 8 | // same as above, but runs exactly one phase 9 | void runMultiPhaseBasicOnce(graph *G, long *C_orig, int basicOpt, long minGraphSize, 10 | double threshold, double C_threshold, int numThreads, int threadsOpt); 11 | 12 | // uses Granell, Arenas, et al. Fast track resistance 13 | void runMultiPhaseBasicFastTrackResistance(graph *G, long *C_orig, int basicOpt, long minGraphSize, 14 | double threshold, double C_threshold, int numThreads, int threadsOpt); 15 | 16 | 17 | void runMultiPhaseBasicApprox(graph *G, long *C_orig, int basicOpt, long minGraphSize, 18 | double threshold, double C_threshold, int numThreads, int threadsOpt, int percentage); 19 | 20 | // Define in parallelLouvianMethod.cpp 21 | double parallelLouvianMethod(graph *G, long *C, int nThreads, double Lower, 22 | double thresh, double *totTime, int *numItr); 23 | 24 | // Define in parallelLouvianMethodApprox.cpp 25 | double parallelLouvianMethodApprox(graph *G, long *C, int nThreads, double Lower, 26 | double thresh, double *totTime, int *numItr, int percentage); 27 | 28 | double parallelLouvianMethodNoMap(graph *G, long *C, int nThreads, double Lower, 29 | double thresh, double *totTime, int *numItr); 30 | 31 | double parallelLouvianMethodScale(graph *G, long *C, int nThreads, double Lower, 32 | double thresh, double *totTime, int *numItr); 33 | 34 | // implements Granell, Arenas, et al. Fast track resistance 35 | // Granell, Clara, Sergio Gomez, and Alex Arenas. "Hierarchical multiresolution method to 36 | // overcome the resolution limit in complex networks." International Journal of Bifurcation 37 | // and Chaos 22, no. 07 (2012): 1250171. 38 | 39 | // Define in parallelLouvianMethodFastTrackResistance.cpp 40 | double parallelLouvianMethodFastTrackResistance(graph *G, long *C, int nThreads, double Lower, 41 | double thresh, double *totTime, int *numItr, int phase, double* rmin, double* finMod); 42 | 43 | // Define in parallelLouvianMethodNoMapFastTrackResistance.cpp 44 | double parallelLouvianMethodNoMapFastTrackResistance(graph *G, long *C, int nThreads, double Lower, 45 | double thresh, double *totTime, int *numItr, int phase, double* rmin, double* finMod); 46 | 47 | // Define in parallelLouvianMethodScaleFastTrackResistance.cpp 48 | double parallelLouvianMethodScaleFastTrackResistance(graph *G, long *C, int nThreads, double Lower, 49 | double thresh, double *totTime, int *numItr, int phase, double* rmin, double* finMod); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /convertSNAPGroundTruthInformation.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | 45 | using namespace std; 46 | 47 | int main(int argc, char** argv) { 48 | 49 | if (argc < 3) { 50 | printf("================================================================================================\n"); 51 | printf("Usage: %s \n", argv[0]); 52 | printf("================================================================================================\n"); 53 | exit(-1); 54 | } 55 | ifstream File; 56 | 57 | parse_SNAP_GroundTruthCommunities(argv[1], argv[2]); 58 | return 0; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /DefineStructure/dataStructureHeap.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef _DEFS_Heap 43 | #define _DEFS_Heap 44 | 45 | /* Heap Data structure and functions */ 46 | #define HEAP_MAX_SIZE 1024 47 | /*An entity: id + weight */ 48 | typedef struct /* the edge data structure */ 49 | { 50 | long id; 51 | double weight; 52 | } term; 53 | 54 | typedef struct 55 | { 56 | long maxsize; /* Maximum size */ 57 | long size; /* Current size */ 58 | term * elements; /* vector of elements */ 59 | } heap; 60 | 61 | void heapInitialize(heap *); /* Initialize to HEAP_MAX_SIZE */ 62 | void heapInitializeToN(heap *myHeap, long n); /* Initialize to n */ 63 | void heapAdd(heap *, term); 64 | void heapRemoveMin(heap *); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /gpu_graph/graphGPU.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef GRAPHGPU_H 43 | #define GRAPHGPU_H 44 | 45 | #include "thrust/device_vector.h" 46 | #include "iostream" 47 | #include"commonconstants.h" 48 | 49 | struct GraphGPU { 50 | // Graph 51 | unsigned int nb_nodes; 52 | unsigned long nb_links; 53 | double total_weight; 54 | 55 | int type; 56 | 57 | //thrust::device_vector degrees; 58 | 59 | thrust::device_vector indices; 60 | 61 | thrust::device_vector links; 62 | thrust::device_vector weights; 63 | thrust::device_vector colors; 64 | void greedyColoring(unsigned int wrpSz); 65 | 66 | //unsigned int nb_neighbors(unsigned int node); 67 | //double weighted_degree(unsigned int node); 68 | 69 | 70 | }; 71 | 72 | 73 | #endif /* GRAPHGPU_H */ 74 | 75 | -------------------------------------------------------------------------------- /gpu_graph/openaddressing.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef OPENADDRESSING_H 43 | #define OPENADDRESSING_H 44 | 45 | #include "hashitem.h" 46 | #include"devconstants.h" 47 | 48 | #ifdef RUNONGPU 49 | 50 | __device__ 51 | #endif 52 | inline unsigned int H1GPU(unsigned int key, unsigned int bucketSize) { 53 | return key % bucketSize; 54 | } 55 | 56 | #ifdef RUNONGPU 57 | 58 | __device__ 59 | #endif 60 | inline unsigned int H2GPU(unsigned int key, unsigned int bucketSize) { 61 | return 1 + (key % (bucketSize - 1)); 62 | } 63 | 64 | #ifdef RUNONGPU 65 | __device__ 66 | #endif 67 | int hashInsertGPU(HashItem* Table, unsigned int* totNrAttempt, unsigned int bucketSize, HashItem *dataItem, float* tot, float wDegNode, float m2, float* bestGain, int* bestDest); 68 | 69 | #ifdef RUNONGPU 70 | __device__ 71 | #endif 72 | int hashSearchGPU(HashItem* Table, unsigned int* totNrAttempt, unsigned int bucketSize, HashItem *dataItem); 73 | 74 | #endif /* OPENADDRESSING_H */ 75 | 76 | -------------------------------------------------------------------------------- /Makefile.old: -------------------------------------------------------------------------------- 1 | #GCC Compilers: 2 | CC = gcc 3 | CPP = g++ 4 | CFLAGS = -g -Ofast -fopenmp -std=c99 5 | CPPFLAGS = -g -Ofast -fopenmp -std=c++0x 6 | 7 | 8 | LDFLAGS = $(CPPFLAGS) 9 | #INCLUDES = . $(METIS_INCLUDE) 10 | INCLUDES = ./DefineStructure/ 11 | IOFOLDER = ./InputsOutput 12 | COFOLDER = ./BasicCommunitiesDetection 13 | UTFOLDER = ./Utility 14 | CLFOLDER = ./Coloring 15 | FSFOLDER = ./FullSyncOptimization 16 | LIBS = -lm 17 | 18 | 19 | TARGET_1 = convertFileToBinary 20 | TARGET_2 = driverForGraphClustering 21 | TARGET_3 = driverForColoring 22 | 23 | TARGET = $(TARGET_1) $(TARGET_2) 24 | # $(TARGET_3) $(TARGET_4) $(TARGET_5) $(TARGET_6) 25 | 26 | #TARGET = $(TARGET_1) $(TARGET_2) $(TARGET_3) $(TARGET_4) 27 | 28 | #TARGET = $(TARGET_9) 29 | 30 | 31 | #IOBJECTS = loadBinary.o loadMetis.o loadMatrixMarket.o \ 32 | loadEdgeList.o 33 | IOFILES = $(wildcard $(IOFOLDER)/*.cpp) 34 | IOOBJECTS = $(addprefix $(IOFOLDER)/,$(notdir $(IOFILES:.cpp=.o))) 35 | 36 | COFILES = $(wildcard $(COFOLDER)/*.cpp) 37 | COOBJECTS = $(addprefix $(COFOLDER)/,$(notdir $(COFILES:.cpp=.o))) 38 | 39 | UTFILES = $(wildcard $(UTFOLDER)/*.cpp) 40 | UTOBJECTS = $(addprefix $(UTFOLDER)/,$(notdir $(UTFILES:.cpp=.o))) 41 | 42 | CLFILES = $(wildcard $(CLFOLDER)/*.cpp) 43 | CLOBJECTS = $(addprefix $(CLFOLDER)/,$(notdir $(CLFILES:.cpp=.o))) 44 | 45 | CLFILES2 = coloringDistanceOne.o equitableColoringDistanceOne.o coloringUtils.cpp 46 | CLOBJECTS2 = $(addprefix $(CLFOLDER)/,$(notdir $(CLFILES2:.cpp=.o))) 47 | 48 | FSFILES = $(wildcard $(FSFOLDER)/*.cpp) 49 | FSOBJECTS = $(addprefix $(FSFOLDER)/,$(notdir $(FSFILES:.cpp=.o))) 50 | 51 | 52 | 53 | #OBJECTS = RngStream.o utilityFunctions.o parseInputFiles.o \ 54 | writeGraphDimacsFormat.o buildNextPhase.o \ 55 | coloringDistanceOne.o utilityClusteringFunctions.o equitableColoringDistanceOne.o\ 56 | parallelLouvainMethod.o parallelLouvainMethodNoMap.o \ 57 | parallelLouvainMethodScale.o parallelLouvainWithColoring.o parallelLouvainWithColoringNoMap.o \ 58 | louvainMultiPhaseRun.o parseInputParameters.o vertexFollowing.o parallelLouvianMethodApprox.o runMultiPhaseBasicApprox.o 59 | 60 | all: $(TARGET) 61 | coloring: $(TARGET_3) 62 | 63 | #message 64 | 65 | $(TARGET_1): $(IOOBJECTS) $(UTOBJECTS) $(TARGET_1).o 66 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_1) $(UTOBJECTS) $(IOOBJECTS) $(TARGET_1).o 67 | 68 | $(TARGET_3): $(IOOBJECTS) $(CLOBJECTS2) $(UTOBJECTS) $(TARGET_3).o 69 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_3) $(IOOBJECTS) $(UTOBJECTS) $(CLOBJECTS2) $(TARGET_3).o 70 | 71 | $(TARGET_2): $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(FSOBJECTS) $(CLOBJECTS) $(TARGET_2).o 72 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_2) $(TARGET_2).o $(FSOBJECTS) $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(CLOBJECTS) $(LIBS) 73 | 74 | 75 | .c.o: 76 | $(CC) $(CFLAGS) -c $< -I$(INCLUDES) -o $@ 77 | 78 | .cpp.o: 79 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 80 | 81 | $(IOFOLDER)/%.o: $(IOFOLDER)/%.cpp 82 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 83 | 84 | $(COFOLDER)/%.o: $(COFOLDER)/%.cpp 85 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 86 | 87 | $(UTFOLDER)/%.o: $(UTFOLDER)/%.cpp 88 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 89 | 90 | 91 | clean: 92 | rm -f $(TARGET_1).o $(TARGET_2).o $(TARGET_3).o $(FSFOLDER)/*.o $(IOFOLDER)/*.o $(COFOLDER)/*.o $(UTFOLDER)/*.o $(CLFOLDER)/*.o ./bin/* 93 | 94 | #wipe: 95 | # rm -f $(TARGET).o $(OBJECTS) $(TARGET) *~ *.bak 96 | 97 | message: 98 | echo "Executables: " $(TARGET) " have been created" 99 | 100 | print-%: ; @echo $*=$($*) 101 | -------------------------------------------------------------------------------- /driverForClusterComparison.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "utilityClusteringFunctions.h" 44 | 45 | using namespace std; 46 | 47 | int main(int argc, char** argv) { 48 | 49 | if (argc < 3) { 50 | printf("================================================================================================\n"); 51 | printf("Usage: %s \n", argv[0]); 52 | printf("================================================================================================\n"); 53 | exit(-1); 54 | } 55 | ifstream File; 56 | //Parse file with ground truth communities: 57 | long N1=0; 58 | vector truthCommunity; 59 | File.open(argv[1]); 60 | long temp; 61 | // TODO FIXME provide choices for 1-based 62 | // and whether to read 1/2 tokens per line 63 | while(!File.eof()) { 64 | File >> temp; 65 | truthCommunity.push_back((long)temp); 66 | } 67 | cout << "\n"; 68 | File.close(); 69 | N1 = truthCommunity.size(); 70 | N1--; 71 | cout<< "Parsed ground truth file with " << N1 << " elements\n"; 72 | 73 | //Parse file with output community: 74 | long N2=0; 75 | vector outputCommunity; 76 | File.open(argv[2]); 77 | while(!File.eof()) { 78 | File >> temp; 79 | outputCommunity.push_back((long)temp); 80 | } 81 | cout << "\n"; 82 | File.close(); 83 | N2 = outputCommunity.size(); 84 | N2--; 85 | cout<< "Parsed output file with " << N2 << " elements\n"; 86 | 87 | //Call the cluster comparison function: 88 | computeCommunityComparisons(truthCommunity, N1, outputCommunity, N2); 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /reserver/convertFileToEdgeList.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | 44 | int main(int argc, char** argv) { 45 | //Parse Input parameters: 46 | clustering_parameters opts; 47 | if (!opts.parse(argc, argv)) { 48 | return -1; 49 | } 50 | int nT = 1; //Default is one thread 51 | #pragma omp parallel 52 | { 53 | nT = omp_get_num_threads(); 54 | } 55 | if (nT <= 1) { 56 | printf("The number of threads should be greater than one.\n"); 57 | return 0; 58 | } 59 | graph* G = (graph *) malloc (sizeof(graph)); 60 | 61 | int fType = opts.ftype; //File type 62 | char *inFile = (char*) opts.inFile; 63 | 64 | if(fType == 1) 65 | parse_MatrixMarket_Sym_AsGraph(G, inFile); 66 | else if(fType == 2) 67 | parse_Dimacs9FormatDirectedNewD(G, inFile); 68 | else if(fType == 3) 69 | parse_PajekFormat(G, inFile); 70 | else if(fType == 4) 71 | loadADJMatrixFormat(G, inFile); 72 | else if(fType == 5) 73 | loadMetisFileFormat(G, inFile); 74 | else if(fType == 6) 75 | parse_DoulbedEdgeList(G, inFile); 76 | else 77 | parse_EdgeListBinary(G, inFile); 78 | 79 | displayGraphCharacteristics(G); 80 | 81 | /* Step : Set up output parameters */ 82 | char buf[512]; 83 | sprintf(buf,"%s.EdgeList", opts.inFile); 84 | printf("%s\n",buf); 85 | FILE* out1 = fopen(buf,"w"); 86 | if(out1 == NULL){ 87 | printf("Really\n"); 88 | exit(1); 89 | } 90 | //displayGraphCharacteristics(G); 91 | writeEdgeListToFile(G, out1); 92 | printf("Done writing the file.\n"); 93 | 94 | /* Step 5: Clean up */ 95 | free(G->edgeListPtrs); 96 | free(G->edgeList); 97 | free(G); 98 | 99 | fclose(out1); 100 | 101 | return 0; 102 | 103 | } 104 | -------------------------------------------------------------------------------- /reserver/convertFileToBinary.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | 44 | using namespace std; 45 | 46 | int main(int argc, char** argv) { 47 | 48 | //Parse Input parameters: 49 | clustering_parameters opts; 50 | if (!opts.parse(argc, argv)) { 51 | return -1; 52 | } 53 | int nT = 1; //Default is one thread 54 | #pragma omp parallel 55 | { 56 | nT = omp_get_num_threads(); 57 | } 58 | if (nT <= 1) { 59 | //printf("The number of threads should be greater than one.\n"); 60 | //return 0; 61 | } 62 | graph* G = (graph *) malloc (sizeof(graph)); 63 | 64 | int fType = opts.ftype; //File type 65 | char *inFile = (char*) opts.inFile; 66 | 67 | parse_Dimacs9FormatDirectedNewD(G, inFile); 68 | /* 69 | if(fType == 1) 70 | parse_MatrixMarket_Sym_AsGraph(G, inFile); 71 | else if(fType == 2) 72 | parse_Dimacs9FormatDirectedNewD(G, inFile); 73 | else if(fType == 3) 74 | parse_PajekFormat(G, inFile); 75 | else if(fType == 4) 76 | loadADJMatrixFormat(G, inFile); 77 | else if(fType == 5 || fType == 9) 78 | loadMetisFileFormat(G, inFile); 79 | else if(fType == 6) 80 | parse_DoulbedEdgeList(G, inFile); 81 | else 82 | parse_EdgeListBinary(G, inFile); 83 | 84 | displayGraphCharacteristics(G); 85 | //displayGraph(G); 86 | 87 | //Save file to binary: 88 | char outFile[256]; 89 | sprintf(outFile,"%s.d10", opts.inFile); 90 | printf("Graph will be stored in binary format in file: %s\n", outFile); 91 | if(fType == 9 || fType == 5) 92 | writeGraphBinaryFormatNew(G, outFile,1); 93 | else 94 | writeGraphBinaryFormat(G,outFile); 95 | // writeGraphMetisSimpleFormat(G, outFile); 96 | */ 97 | //Cleanup: 98 | if(G != 0) { 99 | free(G->edgeListPtrs); 100 | free(G->edgeList); 101 | free(G); 102 | } 103 | 104 | return 0; 105 | }//End of main() 106 | -------------------------------------------------------------------------------- /reserver/convert: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | using namespace std; 45 | 46 | int main(int argc, char** argv) { 47 | 48 | //Parse Input parameters: 49 | clustering_parameters opts; 50 | if (!opts.parse(argc, argv)) { 51 | return -1; 52 | } 53 | int nT = 1; //Default is one thread 54 | #pragma omp parallel 55 | { 56 | nT = omp_get_num_threads(); 57 | } 58 | if (nT <= 1) { 59 | //printf("The number of threads should be greater than one.\n"); 60 | //return 0; 61 | } 62 | graph* G = (graph *) malloc (sizeof(graph)); 63 | 64 | int fType = opts.ftype; //File type 65 | char *inFile = (char*) opts.inFile; 66 | 67 | loaMetisFileFormat(G,inFile); 68 | // parse_Dimacs9FormatDirectedNewD(G, inFile); 69 | /* 70 | if(fType == 1) 71 | parse_MatrixMarket_Sym_AsGraph(G, inFile); 72 | else if(fType == 2) 73 | parse_Dimacs9FormatDirectedNewD(G, inFile); 74 | else if(fType == 3) 75 | parse_PajekFormat(G, inFile); 76 | else if(fType == 4) 77 | loadADJMatrixFormat(G, inFile); 78 | else if(fType == 5 || fType == 9) 79 | loadMetisFileFormat(G, inFile); 80 | else if(fType == 6) 81 | parse_DoulbedEdgeList(G, inFile); 82 | else 83 | parse_EdgeListBinary(G, inFile); 84 | 85 | displayGraphCharacteristics(G); 86 | //displayGraph(G); 87 | 88 | //Save file to binary: 89 | char outFile[256]; 90 | sprintf(outFile,"%s.d10", opts.inFile); 91 | printf("Graph will be stored in binary format in file: %s\n", outFile); 92 | if(fType == 9 || fType == 5) 93 | writeGraphBinaryFormatNew(G, outFile,1); 94 | else 95 | writeGraphBinaryFormat(G,outFile); 96 | // writeGraphMetisSimpleFormat(G, outFile); 97 | */ 98 | //Cleanup: 99 | if(G != 0) { 100 | free(G->edgeListPtrs); 101 | free(G->edgeList); 102 | free(G); 103 | } 104 | 105 | return 0; 106 | }//End of main() 107 | -------------------------------------------------------------------------------- /DefineStructure/coloringUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __ColorUtils__ 2 | #define __ColorUtils__ 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "RngStream.h" 17 | //##include 18 | #include 19 | #include 20 | #include 21 | #include "defs.h" 22 | 23 | 24 | 25 | /*struct MoveInfo 26 | { 27 | ColorElem source; 28 | ColorElem target; 29 | GraphElem numVertices; 30 | GraphElem startPost; 31 | 32 | };*/ 33 | 34 | typedef std::vector BitVector; 35 | typedef std::vector ColorVector; 36 | typedef int ColorElem; 37 | #define MaxDegree 4096 38 | //using namespace std; 39 | 40 | int distanceOneMarkArray(BitVector &mark, graph *G, long v, int *vtxColor); 41 | void computeBinSizes(ColorVector &binSizes, int* colors, long nv, int numColors); 42 | void distanceOneConfResolution(graph* G, long v, int* vtxColor, double* randValues, long* QtmpTail, long* Qtmp, ColorVector& freq, int type); 43 | void distanceOneChecked(graph* G, long nv ,int* colors); 44 | void buildColorsIndex(int* colors, const int numColors, const long nv, ColorVector& colorPtr, ColorVector& colorIndex, ColorVector& binSizes); 45 | 46 | /******* UtiliyFunctions ***** 47 | void computeBinSizes(ColorVector &binSizes, const ColorVector &colors, const GraphElem nv, const ColorElem numColors); 48 | ColorElem getDegree(const GraphElem ci, const Graph &g); 49 | void computeBinSizesWeighted(ColorVector &binSizes, const ColorVector &colors, const GraphElem nv, const ColorElem numColors, const Graph &g); 50 | void outPut(const ColorVector &colors, std::string output, const ColorVector& freq, const ColorElem ncolors); 51 | 52 | void buildColorsIndex(const ColorVector& colors, const ColorElem numColors, const ColorElem nv, ColorVector& colorPtr, ColorVector& colorIndex, ColorVector& binSizes); 53 | 54 | //bool findConflicts(const Graph &g, const ColorElem targetColor, const ColorVector &colors, const GraphElem vertex); 55 | 56 | void distanceOneConfResolution(const Graph &g, const GraphElem &sv, ColorVector &colors, ColorVector &freq, const RandVec& randVec, ColorQueue& qtmp, GraphElem& qtmpPos, int type); 57 | 58 | void distanceOneConfResolutionWeighted(const Graph &g, const GraphElem &sv, ColorVector &colors, ColorVector &freq, const RandVec& randVec, ColorQueue& qtmp, GraphElem& qtmpPos, int type); 59 | 60 | 61 | ColorElem distanceOneMarkArray(BitVector &mark, const Graph &g, const GraphElem &sv, const ColorVector &colors); 62 | 63 | void distanceOneChecked(const Graph &g, const GraphElem nv ,const ColorVector &colors); 64 | void generateRandomNumbers(std::vector &randVec); 65 | 66 | /******* Coloring Functions ****** 67 | 68 | /* Basic coloring (unbalanced) in initialColoring.cpp 69 | ColorElem initColoring(const Graph &g, ColorVector &colors, std::string input); 70 | /* Basic coloiring (ab-inital) in initialColoringLU.cpp 71 | ColorElem initColoringLU(const Graph &g, ColorVector &colors, std::string input); 72 | 73 | /* Vertex base redistribution in vBase.cpp 74 | * type: 0) FF, 1) LU 75 | ColorElem vBaseRedistribution(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors, int type); 76 | ColorElem TrueSerialvBaseRedistribution(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors, int type); 77 | ColorElem wBaseRedistribution(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors, int type); 78 | 79 | 80 | ColorElem mBaseRedistribution(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors, int type); 81 | 82 | /* Color base redistribution in cBase.cpp 83 | * type: 0) FF, 1) LU 84 | ColorElem cBaseRedistribution(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors, int type); 85 | 86 | ColorElem reColor(const Graph &g, ColorVector &baseColors, std::string input, ColorElem ncolors,double factor); 87 | ColorElem schRedistribution(const Graph &g, ColorVector &colors, std::string input, ColorElem ncolors);*/ 88 | #endif 89 | -------------------------------------------------------------------------------- /DefineStructure/utilityClusteringFunctions.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef __CLUSTERING__FUNCTIONS__ 43 | #define __CLUSTERING__FUNCTIONS__ 44 | 45 | #include "defs.h" 46 | 47 | using namespace std; 48 | 49 | void sumVertexDegree(edge* vtxInd, long* vtxPtr, double* vDegree, long NV, Comm* cInfo); 50 | 51 | double calConstantForSecondTerm(double* vDegree, long NV); 52 | 53 | void initCommAss(long* pastCommAss, long* currCommAss, long NV); 54 | 55 | void initCommAssOpt(long* pastCommAss, long* currCommAss, long NV, 56 | mapElement* clusterLocalMap, long* vtxPtr, edge* vtxInd, 57 | Comm* cInfo, double constant, double* vDegree ); 58 | 59 | double buildLocalMapCounter(long adj1, long adj2, map &clusterLocalMap, 60 | vector &Counter, edge* vtxInd, long* currCommAss, long me); 61 | 62 | double buildLocalMapCounterNoMap(long v, mapElement* clusterLocalMap, long* vtxPtr, edge* vtxInd, 63 | long* currCommAss, long &numUniqueClusters); 64 | 65 | long max(map &clusterLocalMap, vector &Counter, 66 | double selfLoop, Comm* cInfo, double degree, long sc, double constant ) ; 67 | 68 | long maxNoMap(long v, mapElement* clusterLocalMap, long* vtxPtr, double selfLoop, Comm* cInfo, double degree, 69 | long sc, double constant, long numUniqueClusters ); 70 | 71 | void computeCommunityComparisons(vector& C1, long N1, vector& C2, long N2); 72 | 73 | double computeGiniCoefficient(long *colorSize, int numColors); 74 | double computeMerkinMetric(long* C1, long N1, long* C2, long N2); 75 | double computeVanDongenMetric(long* C1, long N1, long* C2, long N2); 76 | 77 | //Sorting functions: 78 | void merge(long* arr, long l, long m, long r); 79 | void mergeSort(long* arr, long l, long r); 80 | void SortNeighborListUsingInsertionAndMergeSort(graph *G); 81 | long removeEdges(long NV, long NE, edge *edgeList); 82 | void SortEdgesUndirected(long NV, long NE, edge *list1, edge *list2, long *ptrs); 83 | void SortNodeEdgesByIndex(long NV, edge *list1, edge *list2, long *ptrs); 84 | 85 | double* computeEdgeSimilarityMetrics(graph *G); 86 | graph* buildSparifiedGraph(graph *Gin, double alpha); 87 | 88 | void buildOld2NewMap(long N, long *C, long *commIndex); //Build the reordering map 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /gpu_graph/assignGraph.cu: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include 43 | #include 44 | #include 45 | #include "communityGPU.h" 46 | 47 | void Community::set_new_graph_as_current() { 48 | 49 | g.indices.clear(); 50 | g.links.clear(); 51 | g.weights.clear(); 52 | 53 | g.indices.resize(g_next.nb_nodes + 1); 54 | g.links.resize(g_next.nb_links); 55 | g.weights.resize(g_next.nb_links); 56 | 57 | /* 58 | { 59 | std::cout << std::endl << "[Before Exchange] g.size(): " << g.nb_nodes << std::endl; 60 | } 61 | */ 62 | g = g_next; 63 | 64 | //deep copy or sallow copy ? 65 | { 66 | 67 | g_next.indices.clear(); 68 | g_next.links.clear(); 69 | g_next.weights.clear(); 70 | } 71 | /* 72 | { 73 | std::cout << std::endl << "[After Exchange] g.size(): " << g.nb_nodes << " #E: " << g.links.size() << std::endl; 74 | } 75 | */ 76 | 77 | //std::cout << "...............Set New Graph as Current.................................." << std::endl; 78 | 79 | int sc; 80 | sc = 0; //std::cin>>sc; 81 | if (sc > 0) { 82 | print_vector(g.indices, "g.indices( after exchanging): "); 83 | print_vector(g.weights, "g.weights( after exchanging): "); 84 | print_vector(g.links, "g.links( after exchanging): "); 85 | } 86 | 87 | community_size = g.nb_nodes; 88 | 89 | } 90 | 91 | void Community::readPrimes(std::string filename) { 92 | 93 | std::ifstream filePtr(filename.c_str()); 94 | 95 | if (filePtr.is_open()) { 96 | 97 | int nrPrimes, aPrimeNum; 98 | 99 | filePtr>>nrPrimes; 100 | 101 | assert(nrPrimes > 0); 102 | 103 | std::cout << "Reading " << nrPrimes << " prime numbers." << std::endl; 104 | 105 | //Read primes in host memory 106 | hostPrimes = new int [nrPrimes]; 107 | int index = 0; 108 | while (filePtr >> aPrimeNum) { 109 | 110 | hostPrimes[index++] = aPrimeNum; 111 | if (index >= nrPrimes) 112 | break; 113 | //std::cout << aPrimeNum << " "; 114 | } 115 | 116 | std::cout << std::endl; 117 | 118 | assert(nrPrimes == index); 119 | nb_prime = nrPrimes; 120 | 121 | //Copy prime numbers to device memory 122 | devPrimes.resize(nb_prime); 123 | thrust::copy(hostPrimes, hostPrimes + nb_prime, devPrimes.begin()); 124 | 125 | } else { 126 | std::cout << "Can't open file containing prime numbers." << std::endl; 127 | } 128 | return; 129 | } 130 | 131 | -------------------------------------------------------------------------------- /reserver/convertSnapFileToBinary.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | 44 | using namespace std; 45 | 46 | int main(int argc, char** argv) { 47 | 48 | //Parse Input parameters: 49 | clustering_parameters opts; 50 | if (!opts.parse(argc, argv)) { 51 | return -1; 52 | } 53 | int nT = 1; //Default is one thread 54 | #pragma omp parallel 55 | { 56 | nT = omp_get_num_threads(); 57 | } 58 | if (nT <= 1) { 59 | printf("The number of threads should be greater than one.\n"); 60 | return 0; 61 | } 62 | graph* G = (graph *) malloc (sizeof(graph)); 63 | 64 | int fType = opts.ftype; //File type 65 | char *inFile = (char*) opts.inFile; 66 | 67 | if(fType == 1) 68 | parse_MatrixMarket_Sym_AsGraph(G, inFile); 69 | else if(fType == 2) 70 | parse_Dimacs9FormatDirectedNewD(G, inFile); 71 | else if(fType == 3) 72 | parse_PajekFormat(G, inFile); 73 | else if(fType == 4) 74 | parse_PajekFormatUndirected(G, inFile); 75 | else if(fType == 5) 76 | loadMetisFileFormat(G, inFile); 77 | else if(fType == 6) 78 | parse_DoulbedEdgeList(G, inFile); 79 | else if(fType == 7) 80 | parse_EdgeListBinary(G, inFile); 81 | else 82 | parse_SNAP(G, inFile); 83 | 84 | displayGraphCharacteristics(G); 85 | //displayGraph(G); 86 | 87 | //Clean up the file: 88 | long numVtxToFix = 0; //Default zero 89 | long *C = (long *) malloc (G->numVertices * sizeof(long)); assert(C != 0); 90 | numVtxToFix = vertexFollowing(G,C); //Find vertices that follow other vertices 91 | if( numVtxToFix > 0) { //Need to fix things: build a new graph 92 | printf("Graph will be modified -- %ld vertices need to be fixed.\n", numVtxToFix); 93 | graph *Gnew = (graph *) malloc (sizeof(graph)); 94 | long numClusters = renumberClustersContiguously(C, G->numVertices); 95 | buildNewGraphVF(G, Gnew, C, numClusters); 96 | //Get rid of the old graph and store the new graph 97 | free(G->edgeListPtrs); 98 | free(G->edgeList); 99 | free(G); 100 | G = Gnew; 101 | } 102 | free(C); //Free up memory 103 | 104 | //Display characteristics 105 | displayGraphCharacteristics(G); 106 | 107 | //Save file to binary: 108 | char outFile[256]; 109 | sprintf(outFile,"%s.bin", opts.inFile); 110 | printf("Graph will be stored in binary format in file: %s\n", outFile); 111 | writeGraphBinaryFormat(G, outFile); 112 | 113 | //Cleanup: 114 | if(G != 0) { 115 | free(G->edgeListPtrs); 116 | free(G->edgeList); 117 | free(G); 118 | } 119 | 120 | return 0; 121 | }//End of main() 122 | -------------------------------------------------------------------------------- /gpu_graph/computeModularity.cu: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include 43 | #include 44 | #include "communityGPU.h" 45 | 46 | struct my_modularity_functor_2 { 47 | double m2; 48 | 49 | #ifdef RUNONGPU 50 | 51 | __host__ __device__ 52 | #endif 53 | 54 | my_modularity_functor_2(double _m2) : m2(_m2) { 55 | } 56 | 57 | #ifdef RUNONGPU 58 | 59 | __host__ __device__ 60 | #endif 61 | 62 | double operator()(const float& x, const float& y) { 63 | return ((double) x / m2 - ((double) y / m2)*((double) y / m2)); 64 | } 65 | 66 | }; 67 | 68 | double Community::modularity(thrust::device_vector& tot, thrust::device_vector& in) { // put i=j in equation (1) 69 | 70 | float q = 0.; 71 | float m2 = (float) g.total_weight; 72 | 73 | std::cout << "m2: " << m2 << std::endl; 74 | 75 | /* 76 | thrust::host_vector in_ = in; 77 | thrust::host_vector tot_ = tot; 78 | //std::cout << "QQ:" << std::endl; 79 | for (int i = 0; i < community_size; i++) { 80 | if (tot_[i] > 0) { 81 | //std::cout << in_[i] << " " << tot_[i] << " " << m2 << " : "; 82 | q += in_[i] / m2 - (tot_[i] / m2)*(tot_[i] / m2); 83 | } 84 | } 85 | //std::cout << std::endl; 86 | return q; 87 | */ 88 | 89 | /* 90 | double q = 0.; 91 | double m2 = (double) g.total_weight; 92 | 93 | for (int i = 0; i < size; i++) { 94 | if (tot[i] > 0) 95 | q += (double) in[i] / m2 - ((double) tot[i] / m2)*((double) tot[i] / m2); 96 | } 97 | 98 | return q; 99 | */ 100 | 101 | bool hostPrint = false; 102 | 103 | if (hostPrint) { 104 | std::cout << std::endl << " Inside modularity() " << std::endl; 105 | 106 | thrust::copy(tot.begin(), tot.end(), std::ostream_iterator(std::cout, " ")); 107 | std::cout << std::endl; 108 | 109 | thrust::copy(in.begin(), in.end(), std::ostream_iterator(std::cout, " ")); 110 | std::cout << std::endl; 111 | } 112 | 113 | int sc; 114 | //std::cout << community_size << " |in|:" << in.size() << " |tot|:" << tot.size() << std::endl; 115 | 116 | sc = 0; //std::cin>>sc; 117 | thrust::device_vector result_array(community_size, 0.0); 118 | sc = 0; //std::cin>>sc; 119 | 120 | thrust::transform(thrust::device, in.begin(), in.end(), tot.begin(), result_array.begin(), my_modularity_functor_2(m2)); 121 | 122 | q = thrust::reduce(thrust::device, result_array.begin(), result_array.end(), (double) 0, thrust::plus()); 123 | result_array.clear(); 124 | return q; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /Makefile-HDF5: -------------------------------------------------------------------------------- 1 | #GCC Compilers: 2 | CC = gcc 3 | CPP = g++ 4 | CFLAGS = -g -Ofast -fopenmp -std=c99 5 | CPPFLAGS = -g -Ofast -fopenmp -std=c++11 6 | #-Ofast 7 | 8 | LDFLAGS = $(CPPFLAGS) 9 | #INCLUDES = . $(METIS_INCLUDE) 10 | INCLUDES = ./DefineStructure/ 11 | IOFOLDER = ./InputsOutput 12 | COFOLDER = ./BasicCommunitiesDetection 13 | UTFOLDER = ./Utility 14 | CLFOLDER = ./Coloring 15 | FSFOLDER = ./FullSyncOptimization 16 | LIBS = -lm 17 | 18 | 19 | TARGET_1 = convertFileToBinary 20 | TARGET_2 = driverForGraphClusteringApprox 21 | TARGET_3 = driverForColoring 22 | TARGET_4 = driverForGraphClustering 23 | TARGET = $(TARGET_1) $(TARGET_2) $(TARGET_4) 24 | # $(TARGET_3) $(TARGET_4) $(TARGET_5) $(TARGET_6) 25 | 26 | #TARGET = $(TARGET_1) $(TARGET_2) $(TARGET_3) $(TARGET_4) 27 | 28 | #TARGET = $(TARGET_9) 29 | 30 | 31 | #IOBJECTS = loadBinary.o loadMetis.o loadMatrixMarket.o \ 32 | loadEdgeList.o 33 | IOFILES = $(wildcard $(IOFOLDER)/*.cpp) 34 | IOOBJECTS = $(addprefix $(IOFOLDER)/,$(notdir $(IOFILES:.cpp=.o))) 35 | 36 | COFILES = $(wildcard $(COFOLDER)/*.cpp) 37 | COOBJECTS = $(addprefix $(COFOLDER)/,$(notdir $(COFILES:.cpp=.o))) 38 | 39 | UTFILES = $(wildcard $(UTFOLDER)/*.cpp) 40 | UTOBJECTS = $(addprefix $(UTFOLDER)/,$(notdir $(UTFILES:.cpp=.o))) 41 | 42 | CLFILES = $(wildcard $(CLFOLDER)/*.cpp) 43 | CLOBJECTS = $(addprefix $(CLFOLDER)/,$(notdir $(CLFILES:.cpp=.o))) 44 | 45 | CLFILES2 = coloringDistanceOne.o equitableColoringDistanceOne.o coloringUtils.cpp 46 | CLOBJECTS2 = $(addprefix $(CLFOLDER)/,$(notdir $(CLFILES2:.cpp=.o))) 47 | 48 | FSFILES = $(wildcard $(FSFOLDER)/*.cpp) 49 | FSOBJECTS = $(addprefix $(FSFOLDER)/,$(notdir $(FSFILES:.cpp=.o))) 50 | 51 | 52 | 53 | #OBJECTS = RngStream.o utilityFunctions.o parseInputFiles.o \ 54 | writeGraphDimacsFormat.o buildNextPhase.o \ 55 | coloringDistanceOne.o utilityClusteringFunctions.o equitableColoringDistanceOne.o\ 56 | parallelLouvainMethod.o parallelLouvainMethodNoMap.o \ 57 | parallelLouvainMethodScale.o parallelLouvainWithColoring.o parallelLouvainWithColoringNoMap.o \ 58 | louvainMultiPhaseRun.o parseInputParameters.o vertexFollowing.o parallelLouvianMethodApprox.o runMultiPhaseBasicApprox.o 59 | 60 | all: $(TARGET) 61 | coloring: $(TARGET_3) 62 | 63 | #message 64 | 65 | $(TARGET_1): $(IOOBJECTS) $(UTOBJECTS) $(TARGET_1).o 66 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_1) $(UTOBJECTS) $(IOOBJECTS) $(TARGET_1).o 67 | 68 | $(TARGET_3): $(IOOBJECTS) $(CLOBJECTS2) $(UTOBJECTS) $(TARGET_3).o 69 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_3) $(IOOBJECTS) $(UTOBJECTS) $(CLOBJECTS2) $(TARGET_3).o 70 | 71 | $(TARGET_2): $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(FSOBJECTS) $(CLOBJECTS) $(TARGET_2).o 72 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_2) $(TARGET_2).o $(FSOBJECTS) $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(CLOBJECTS) $(LIBS) 73 | 74 | $(TARGET_4): $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(FSOBJECTS) $(CLOBJECTS) $(TARGET_4).o 75 | $(CPP) $(LDFLAGS) -o ./bin/$(TARGET_4) $(TARGET_4).o $(FSOBJECTS) $(IOOBJECTS) $(COOBJECTS) $(UTOBJECTS) $(CLOBJECTS) $(LIBS) 76 | 77 | .c.o: 78 | $(CC) $(CFLAGS) -c $< -I$(INCLUDES) -o $@ 79 | 80 | .cpp.o: 81 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 82 | 83 | $(IOFOLDER)/%.o: $(IOFOLDER)/%.cpp 84 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 85 | 86 | $(COFOLDER)/%.o: $(COFOLDER)/%.cpp 87 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 88 | 89 | $(UTFOLDER)/%.o: $(UTFOLDER)/%.cpp 90 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -o $@ 91 | 92 | 93 | clean: 94 | rm -f $(TARGET_1).o $(TARGET_2).o $(TARGET_3).o $(FSFOLDER)/*.o $(IOFOLDER)/*.o $(COFOLDER)/*.o $(UTFOLDER)/*.o $(CLFOLDER)/*.o ./bin/* blosc_filter/*.so 95 | 96 | #wipe: 97 | # rm -f $(TARGET).o $(OBJECTS) $(TARGET) *~ *.bak 98 | 99 | message: 100 | echo "Executables: " $(TARGET) " have been created" 101 | 102 | print-%: ; @echo $*=$($*) 103 | 104 | 105 | #HDF5 PARSER 106 | 107 | TARGET_H5 = driverForGraphClusteringH5 108 | 109 | BLOSC_FILTER_ROOT=blosc_filter 110 | BLOSC_FILTER_LIB=$(BLOSC_FILTER_ROOT)/blosc_filter.so 111 | HDF_INC=$(HDF5_ROOT)/include 112 | HDF_LIB=$(HDF5_ROOT)/lib 113 | 114 | IOFILESH5 = $(wildcard $(IOFOLDER)/*.cc) 115 | IOOBJECTSH5 = $(addprefix $(IOFOLDER)/,$(notdir $(IOFILESH5:.cc=.o))) 116 | 117 | $(TARGET_H5): $(BLOSC_FILTER_LIB) $(IOOBJECTS) $(IOOBJECTSH5) $(COOBJECTS) $(UTOBJECTS) $(FSOBJECTS) $(CLOBJECTS) $(TARGET_4).o 118 | $(CPP) -DUSEHDF5 $(LDFLAGS) -o ./bin/$(TARGET_H5) $(TARGET_4).o $(BLOSC_FILTER_LIB) $(FSOBJECTS) \ 119 | $(IOOBJECTS) $(IOOBJECTSH5) $(COOBJECTS) $(UTOBJECTS) $(CLOBJECTS) $(LIBS) -L$(BLOSC_ROOT)/lib -lblosc -L$(HDF_LIB) -lhdf5 -lhdf5_cpp 120 | 121 | $(IOFOLDER)/%.o: $(IOFOLDER)/%.cc 122 | $(CPP) $(CPPFLAGS) -c $< -I$(INCLUDES) -I$(HDF_INC) -I$(BLOSC_ROOT)/include -I$(BLOSC_FILTER_ROOT) -o $@ 123 | 124 | $(BLOSC_FILTER_LIB): 125 | make -C $(BLOSC_FILTER_ROOT) 126 | -------------------------------------------------------------------------------- /convertFileToBinary.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | #include "basic_util.h" 45 | using namespace std; 46 | 47 | int main(int argc, char** argv) { 48 | 49 | //Parse Input parameters: 50 | clustering_parameters opts; 51 | if (!opts.parse(argc, argv)) { 52 | return -1; 53 | } 54 | int nT = 1; //Default is one thread 55 | #pragma omp parallel 56 | { 57 | nT = omp_get_num_threads(); 58 | } 59 | if (nT <= 1) { 60 | //printf("The number of threads should be greater than one.\n"); 61 | //return 0; 62 | } 63 | graph* G = (graph *) malloc (sizeof(graph)); 64 | 65 | int fType = opts.ftype; //File type 66 | char *inFile = (char*) opts.inFile; 67 | 68 | switch (fType) { 69 | case 1: parse_MatrixMarket_Sym_AsGraph(G, inFile); break; 70 | case 2: parse_Dimacs9FormatDirectedNewD(G, inFile); break; 71 | case 3: parse_PajekFormat(G, inFile); break; 72 | case 4: parse_PajekFormatUndirected(G, inFile); break; 73 | case 5: loadMetisFileFormat(G, inFile); break; 74 | case 6: parse_UndirectedEdgeList(G, inFile); break; 75 | //parse_UndirectedEdgeListDarpaHive(G, inFile); break; 76 | case 7: printf("Not available\n"); exit(1); break; //parse_DirectedEdgeList(G, inFile); break; 77 | case 8: parse_SNAP(G, inFile); break; 78 | case 9: parse_EdgeListBinaryNew(G,inFile); break; 79 | case 10: 80 | #ifdef USEHDF5 81 | //parse_EdgeListCompressedHDF5(G,inFile); 82 | parse_EdgeListCompressedHDF5NoDuplicates(G,inFile); 83 | #endif 84 | break; 85 | case 11: parse_UndirectedEdgeListFromJason(G, inFile); break; 86 | case 12: parse_UndirectedEdgeListWeighted(G, inFile); break; // for John F's graphs 87 | case 13: parse_UndirectedEdgeListDarpaHive(G, inFile); break; 88 | case 14: parse_EdgeListFromGorder(G, inFile); break; 89 | default: cout<<"A valid file type has not been specified"<edgeListPtrs); 111 | free(G->edgeList); 112 | free(G); 113 | } 114 | 115 | return 0; 116 | }//End of main() 117 | -------------------------------------------------------------------------------- /InputsOutput/writeSimple.cpp: -------------------------------------------------------------------------------- 1 | #include "input_output.h" 2 | void writeGraphMetisSimpleFormat(graph* G, char *filename) { 3 | //Get the iterators for the graph: 4 | long NVer = G->numVertices; 5 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 6 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 7 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 8 | 9 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 10 | printf("Writing graph in Metis format - each edge represented twice -- no weights; 1-based indices\n"); 11 | printf("Graph will be stored in file: %s\n", filename); 12 | 13 | FILE *fout; 14 | fout = fopen(filename, "w"); 15 | if (!fout) { 16 | printf("Could not open the file \n"); 17 | exit(1); 18 | } 19 | //First Line: #Vertices #Edges 20 | fprintf(fout, "%ld %ld\n", NVer, NEdge); 21 | //Write the edges: 22 | for (long v=0; vnumVertices; 39 | long NS = G->sVertices; 40 | long NT = NVer - NS; 41 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 42 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 43 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 44 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 45 | 46 | printf("Writing graph in Pajek format - Undirected graph - each edge represented ONLY ONCE!\n"); 47 | printf("Graph will be stored in file: %s\n", filename); 48 | 49 | 50 | FILE *fout; 51 | fout = fopen(filename, "w"); 52 | if (!fout) { 53 | printf("Could not open the file \n"); 54 | exit(1); 55 | } 56 | //First Line: Vertices 57 | fprintf(fout, "*Vertices %ld\n", NVer); 58 | for (long i=0; i 68 | for(long k = adj1; k < adj2; k++ ) { 69 | if (v <= verInd[k].tail) { //Print only once 70 | fprintf(fout, "%ld %ld %g\n", v+1, (verInd[k].tail+1), (verInd[k].weight) ); 71 | } 72 | } 73 | } 74 | fclose(fout); 75 | printf("Graph has been stored in file: %s\n",filename); 76 | }//End of writeGraphPajekFormat() 77 | 78 | //Output the graph in Pajek format: 79 | //Each edge is represented twice 80 | void writeGraphPajekFormatWithCommunityInfo(graph* G, char *filename, long *C) { 81 | //Get the iterators for the graph: 82 | long NVer = G->numVertices; 83 | long NS = G->sVertices; 84 | long NT = NVer - NS; 85 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 86 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 87 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 88 | 89 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 90 | printf("Writing graph in Pajek format - Undirected graph - each edge represented ONLY ONCE!\n"); 91 | printf("Graph will be stored in file: %s\n", filename); 92 | 93 | FILE *fout; 94 | fout = fopen(filename, "w"); 95 | if (!fout) { 96 | printf("Could not open the file \n"); 97 | exit(1); 98 | } 99 | //First Line: Vertices 100 | fprintf(fout, "*Vertices %ld\n", NVer); 101 | for (long i=0; i 110 | for(long k = adj1; k < adj2; k++ ) { 111 | if (v <= verInd[k].tail) { //Print only once 112 | fprintf(fout, "%ld %ld %g\n", v+1, (verInd[k].tail+1), (verInd[k].weight) ); 113 | } 114 | } 115 | } 116 | fclose(fout); 117 | printf("Graph has been stored in file: %s\n", filename); 118 | }//End of writeGraphPajekFormat() 119 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Nitin A. Gawande, PNNL 2 | # Oct 19, 2018 3 | 4 | PROJECT(GRAPPOLO C CXX) 5 | 6 | option( DEFINE_RUNONGPU "Use of GPU" ON) 7 | IF( DEFINE_RUNONGPU ) 8 | MESSAGE( "GPU code enabled with CUDA" ) 9 | FIND_PACKAGE(CUDA) 10 | ADD_DEFINITIONS( -DRUNONGPU=1 ) 11 | ENDIF( DEFINE_RUNONGPU ) 12 | 13 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 14 | 15 | cmake_minimum_required( VERSION 3.8 ) 16 | 17 | # Include cmake modules 18 | list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ) 19 | 20 | # Project options 21 | option( BUILD_SHARED_LIBS 22 | "Build shared libraries instead of static libraries." 23 | OFF ) 24 | option( OPTION_SELF_CONTAINED 25 | "Create a self-contained install with all dependencies." 26 | OFF ) 27 | option( OPTION_BUILD_TESTS 28 | "Build tests." 29 | ON ) 30 | option( OPTION_BUILD_DOCS 31 | "Build documentation." 32 | OFF ) 33 | option( OPTION_BUILD_EXAMPLES 34 | "Build examples." 35 | OFF ) 36 | 37 | set( CMAKE_CXX_STANDARD 11 ) 38 | 39 | #set(CMAKE_C_COMPILER "gcc-8") 40 | #set(CMAKE_CXX_COMPILER "g++-8") 41 | #set(CMAKE_C_COMPILER "/share/apps/gcc/7.1/bin/gcc") 42 | #set(CMAKE_CXX_COMPILER "/share/apps/gcc/7.1/bin/g++") 43 | 44 | #set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp -O3" ) 45 | set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -fopenmp -O0" ) 46 | 47 | find_package(OpenMP) 48 | if (OPENMP_FOUND) 49 | #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") 50 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 51 | endif() 52 | 53 | # set varaibles using nomenclature used in Makefile 54 | set( IOFOLDER InputsOutput ) 55 | set( COFOLDER BasicCommunitiesDetection ) 56 | set( UTFOLDER Utility ) 57 | set( CLFOLDER Coloring ) 58 | set( FSFOLDER FullSyncOptimization ) 59 | set( DEFINSTR DefineStructure ) 60 | 61 | IF( DEFINE_RUNONGPU ) 62 | MESSAGE( "Use GPU code in gpu_graph directory" ) 63 | set( GPUFOLDER gpu_graph ) 64 | add_subdirectory( gpu_graph ) 65 | ENDIF( DEFINE_RUNONGPU ) 66 | 67 | set( IO_HEADERS 68 | ${CMAKE_SOURCE_DIR}/DefineStructure 69 | ) 70 | 71 | add_subdirectory( InputsOutput ) 72 | add_subdirectory( BasicCommunitiesDetection ) 73 | add_subdirectory( Utility ) 74 | add_subdirectory( Coloring ) 75 | add_subdirectory( FullSyncOptimization ) 76 | 77 | 78 | #set( TARGET_1 convertFileToBinary ) 79 | #set( TARGET_2 driverForGraphClusteringApprox ) 80 | #set( TARGET_3 driverForColoring ) 81 | set( TARGET_4 driverForGraphClustering ) 82 | #set( TARGET_6 driverForGraphClusteringFastTrackResistance ) 83 | set( TARGET_7 driverForClusterComparison ) 84 | #set( TARGET_8 convertSNAPGroundTruthInformation ) 85 | set( TARGET_9 driverForMatrixReordering ) 86 | set( TARGET_10 driverForMatrixReorderingRcm ) 87 | #set( TARGET_11 driverForPartitioningWithMetis ) 88 | #set( TARGET_12 driverForMatrixReorderingND ) 89 | 90 | #add_executable( ${TARGET_1} ${CMAKE_SOURCE_DIR}/${TARGET_1}.cpp ) 91 | #add_executable( ${TARGET_2} ${CMAKE_SOURCE_DIR}/${TARGET_2}.cpp ) 92 | #add_executable( ${TARGET_3} ${CMAKE_SOURCE_DIR}/${TARGET_3}.cpp ) 93 | add_executable( ${TARGET_4} ${CMAKE_SOURCE_DIR}/${TARGET_4}.cpp ) 94 | #add_executable( ${TARGET_5} ${CMAKE_SOURCE_DIR}/${TARGET_5}.cpp ) 95 | #add_executable( ${TARGET_6} ${CMAKE_SOURCE_DIR}/${TARGET_6}.cpp ) 96 | add_executable( ${TARGET_7} ${CMAKE_SOURCE_DIR}/${TARGET_7}.cpp ) 97 | #add_executable( ${TARGET_8} ${CMAKE_SOURCE_DIR}/${TARGET_8}.cpp ) 98 | add_executable( ${TARGET_9} ${CMAKE_SOURCE_DIR}/${TARGET_9}.cpp ) 99 | add_executable( ${TARGET_10} ${CMAKE_SOURCE_DIR}/${TARGET_10}.cpp ) 100 | #add_executable( ${TARGET_11} ${CMAKE_SOURCE_DIR}/${TARGET_11}.cpp ) 101 | #add_executable( ${TARGET_12} ${CMAKE_SOURCE_DIR}/${TARGET_12}.cpp ) 102 | 103 | target_include_directories( ${TARGET_4} 104 | PUBLIC ${IO_HEADERS} 105 | ) 106 | 107 | target_link_libraries( ${TARGET_4} 108 | inout 109 | basic_cd 110 | util 111 | full_syn_opt 112 | coloring 113 | ) 114 | 115 | target_link_libraries( ${TARGET_7} 116 | inout 117 | util 118 | ) 119 | 120 | target_link_libraries( ${TARGET_9} 121 | inout 122 | basic_cd 123 | util 124 | full_syn_opt 125 | coloring 126 | ) 127 | 128 | target_link_libraries( ${TARGET_10} 129 | inout 130 | basic_cd 131 | util 132 | full_syn_opt 133 | coloring 134 | ) 135 | 136 | #target_link_libraries( ${TARGET_10} LINK_PUBLIC 137 | # ${inout} ${basic_cd} ${util} ${full_syn_opt} ${full_syn_opt} ${coloring} ) 138 | 139 | 140 | 141 | install( TARGETS 142 | ${TARGET_4} 143 | ${TARGET_7} 144 | ${TARGET_9} 145 | ${TARGET_10} 146 | DESTINATION bin 147 | ) 148 | 149 | #target_include_directories( ${TARGET_4} PUBLIC ${CMAKE_SOURCE_DIR}/${DEFINSTR} ) 150 | #target_include_directories( ${TARGET_7} PUBLIC ${CMAKE_SOURCE_DIR}/${DEFINSTR} ) 151 | #target_include_directories( ${TARGET_9} PUBLIC ${CMAKE_SOURCE_DIR}/${DEFINSTR} ) 152 | #target_include_directories( ${TARGET_10} PUBLIC ${CMAKE_SOURCE_DIR}/${DEFINSTR} ) 153 | 154 | -------------------------------------------------------------------------------- /gpu_graph/graphHOST.h: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #ifndef GRAPHHOST_H 43 | #define GRAPHHOST_H 44 | 45 | //#include"thrust/host_vector.h" 46 | #include"vector" 47 | #include"assert.h" 48 | #include"commonconstants.h" 49 | class GraphHOST { 50 | public: 51 | unsigned int nb_nodes; 52 | unsigned long nb_links; 53 | double total_weight; 54 | /* 55 | thrust::host_vector degrees; 56 | thrust::host_vector links; 57 | thrust::host_vector weights; 58 | */ 59 | 60 | std::vector degrees; 61 | std::vector links; 62 | std::vector weights; 63 | 64 | GraphHOST(); 65 | 66 | GraphHOST(char *filename, char *filename_w, int type); 67 | 68 | // return the weighted degree of the node 69 | inline double weighted_degree(unsigned int node); 70 | 71 | // return the number of neighbors (degree) of the node 72 | inline unsigned int nb_neighbors(unsigned int node); 73 | 74 | //inline thrust::pair::iterator, thrust::host_vector::iterator >neighbors(unsigned int node); 75 | inline std::pair::iterator, std::vector::iterator >neighbors(unsigned int node); 76 | 77 | void display(); 78 | 79 | }; 80 | 81 | inline unsigned int 82 | GraphHOST::nb_neighbors(unsigned int node) { 83 | assert(node >= 0 && node < nb_nodes); 84 | 85 | if (node == 0) 86 | return degrees[0]; 87 | else 88 | return degrees[node] - degrees[node - 1]; 89 | } 90 | 91 | //inline thrust::pair::iterator, thrust::host_vector::iterator > 92 | 93 | inline std::pair::iterator, std::vector::iterator > 94 | GraphHOST::neighbors(unsigned int node) { 95 | assert(node >= 0 && node < nb_nodes); 96 | 97 | if (node == 0) 98 | return std::make_pair(links.begin(), weights.begin()); 99 | else if (weights.size() != 0) 100 | return std::make_pair(links.begin() + degrees[node - 1], weights.begin() + degrees[node - 1]); 101 | else 102 | return std::make_pair(links.begin() + degrees[node - 1], weights.begin()); 103 | } 104 | 105 | inline double 106 | GraphHOST::weighted_degree(unsigned int node) { 107 | assert(node >= 0 && node < nb_nodes); 108 | 109 | if (weights.size() == 0) 110 | return (double) nb_neighbors(node); 111 | else { 112 | //thrust::pair::iterator, thrust::host_vector::iterator > p = neighbors(node); 113 | std::pair::iterator, std::vector::iterator> p = neighbors(node); 114 | double res = 0; 115 | for (unsigned int i = 0; i < nb_neighbors(node); i++) { 116 | res += (double) *(p.second + i); 117 | } 118 | return res; 119 | } 120 | } 121 | 122 | #endif /* GRAPHHOST_H */ 123 | 124 | -------------------------------------------------------------------------------- /gpu_graph/graphHOST.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include"graphHOST.h" 43 | #include"fstream" 44 | #include "iostream" 45 | #include"vector" 46 | using namespace std; 47 | 48 | GraphHOST::GraphHOST(char* filename, char* filename_w, int type) { 49 | 50 | ifstream finput; 51 | finput.open(filename, fstream::in | fstream::binary); 52 | 53 | // Read number of nodes on 4 bytes 54 | finput.read((char *) &nb_nodes, 4); 55 | assert(finput.rdstate() == ios::goodbit); 56 | 57 | // Read cumulative degree sequence: 8 bytes for each node 58 | // cum_degree[0]=degree(0); cum_degree[1]=degree(0)+degree(1), etc. 59 | degrees.resize(nb_nodes); 60 | finput.read((char *) °rees[0], nb_nodes * 8); 61 | 62 | // Read links: 4 bytes for each link (each link is counted twice) 63 | nb_links = degrees[nb_nodes - 1]; 64 | links.resize(nb_links); 65 | finput.read((char *) (&links[0]), (long) nb_links * 4); 66 | 67 | // IF WEIGHTED : read weights: 4 bytes for each link (each link is counted twice) 68 | weights.resize(0); 69 | 70 | if (type == WEIGHTED) { 71 | ifstream finput_w; 72 | finput_w.open(filename_w, fstream::in | fstream::binary); 73 | weights.resize(nb_links); 74 | finput_w.read((char *) &weights[0], (long) nb_links * 4); 75 | 76 | } 77 | 78 | // Compute total weight 79 | total_weight = 0; 80 | for (unsigned int i = 0; i < nb_nodes; i++) { 81 | total_weight += (double) weighted_degree(i); 82 | } 83 | if (type == UNWEIGHTED) { 84 | std::cout << std::endl << "UNWEIGHTED" << std::endl; 85 | } else { 86 | std::cout << std::endl << "WEIGHTED" << std::endl; 87 | } 88 | std::cout << " total_weight = " << total_weight << std::endl; 89 | } 90 | 91 | GraphHOST::GraphHOST() { 92 | nb_nodes = 0; 93 | nb_links = 0; 94 | total_weight = 0; 95 | } 96 | 97 | void 98 | GraphHOST::display() { 99 | 100 | 101 | 102 | for (unsigned int node = 0; node < nb_nodes; node++) { 103 | pair::iterator, vector::iterator > p = neighbors(node); 104 | //thrust::pair::iterator, thrust::host_vector::iterator > p = neighbors(node); 105 | /* 106 | if (node >= 31220 && node <= 31223) 107 | cout << "node: " << node << " : nr_neighbor: " << nb_neighbors(node) << endl; 108 | 109 | if (node == 34693) 110 | cout << "node: " << node << " : nr_neighbor: " << nb_neighbors(node) << endl; 111 | */ 112 | cout << node << " : "; 113 | for (unsigned int i = 0; i < nb_neighbors(node); i++) { 114 | if (true) { 115 | if (weights.size() != 0) 116 | cout << " (" << *(p.first + i) << " " << *(p.second + i) << ")"; 117 | else 118 | cout << " " << *(p.first + i); 119 | } 120 | } 121 | cout << endl; 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /driverForPartitioningWithMetis.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | #include "basic_comm.h" 45 | #include "basic_util.h" 46 | #include "utilityClusteringFunctions.h" 47 | #include "color_comm.h" 48 | #include "sync_comm.h" 49 | #include "utilityGraphPartitioner.h" 50 | 51 | using namespace std; 52 | //#define USEHDF5 53 | 54 | int main(int argc, char** argv) { 55 | 56 | //Parse Input parameters: 57 | clustering_parameters opts; 58 | if (!opts.parse(argc, argv)) { 59 | return -1; 60 | } 61 | int nT = 1; //Default is one thread 62 | #pragma omp parallel 63 | { 64 | nT = omp_get_num_threads(); 65 | } 66 | if (nT <= 1) { 67 | printf("The number of threads should be greater than one.\n"); 68 | return 0; 69 | } 70 | double time1, time2; 71 | graph* G = (graph *) malloc (sizeof(graph)); 72 | 73 | /* Step 2: Parse the graph in Matrix Market format */ 74 | int fType = opts.ftype; //File type 75 | char *inFile = (char*) opts.inFile; 76 | bool isSym = true; //Assume symmetric by default 77 | switch (fType) { 78 | case 1: isSym = parse_MatrixMarket(G, inFile); break; 79 | case 2: parse_Dimacs9FormatDirectedNewD(G, inFile); break; 80 | case 3: parse_PajekFormat(G, inFile); break; 81 | case 4: parse_PajekFormatUndirected(G, inFile); break; 82 | case 5: loadMetisFileFormat(G, inFile); break; 83 | case 6: //parse_UndirectedEdgeList(G, inFile); 84 | parse_UndirectedEdgeListDarpaHive(G, inFile); break; 85 | case 7: parse_DirectedEdgeList(G, inFile); break; 86 | case 8: parse_SNAP(G, inFile); break; 87 | case 9: parse_EdgeListBinaryNew(G,inFile); break; 88 | case 10: 89 | #ifdef USEHDF5 90 | //parse_EdgeListCompressedHDF5(G,inFile); 91 | parse_EdgeListCompressedHDF5NoDuplicates(G,inFile); 92 | #endif 93 | break; 94 | default: cout<<"A valid file type has not been specified"<numVertices; 104 | long *vPart = (long *) malloc (NV * sizeof(long)); assert(vPart != 0); 105 | 106 | int myVec[7]={2,4,8,16,24,32,36}; 107 | for (int i=0; i<7; i++) { 108 | char outFile[256]; 109 | sprintf(outFile,"%s_%d", opts.inFile, myVec[i]); 110 | printf("Processing with %d partitions; will be stored in file: %s\n", myVec[i], outFile); 111 | MetisGraphPartitioner( G, vPart, myVec[i]); 112 | FILE* out = fopen(outFile,"w"); 113 | for(long i = 0; iedgeListPtrs); 124 | free(G->edgeList); 125 | free(G); 126 | } 127 | free(vPart); 128 | 129 | return 0; 130 | }//End of main() 131 | -------------------------------------------------------------------------------- /gpu_graph/communityGPU.cu: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include 43 | #include 44 | #include "communityGPU.h" 45 | 46 | #include 47 | #include"numeric" 48 | 49 | Community::Community(const GraphHOST& input_graph, int nb_pass, double min_mod) { 50 | 51 | 52 | //Graph 53 | g.nb_links = input_graph.nb_links; 54 | g.nb_nodes = input_graph.nb_nodes; 55 | g.type = UNWEIGHTED; 56 | 57 | 58 | 59 | //Copy degree array into indices with an extra zero(0) at the beginning 60 | g.indices = thrust::device_vector(input_graph.nb_nodes + 1, 0); 61 | thrust::copy(input_graph.degrees.begin(), input_graph.degrees.end(), g.indices.begin() + 1); // 0 at first position 62 | 63 | /********************Gather Graph Statistics***************/ 64 | std::vector< int> vtxDegs; 65 | 66 | vtxDegs.resize(input_graph.degrees.size()); 67 | 68 | std::adjacent_difference(input_graph.degrees.begin(), input_graph.degrees.end(), vtxDegs.begin()); 69 | 70 | int totNbrs = std::accumulate(vtxDegs.begin(), vtxDegs.end(), 0); 71 | int maxDeg = *std::max_element(vtxDegs.begin(), vtxDegs.end()); 72 | 73 | double sumSquareDiff = 0; 74 | double avgDeg = (double) totNbrs / g.nb_nodes; 75 | 76 | for (int i = 0; i < vtxDegs.size(); i++) { 77 | double delta = ((double) vtxDegs[i] - avgDeg); 78 | sumSquareDiff += delta*delta; 79 | } 80 | 81 | double standardDeviation = sqrt(sumSquareDiff / input_graph.nb_nodes); 82 | 83 | std::cout << "MaxDeg = " << maxDeg << " AvgDeg = " << avgDeg << " STD = " 84 | << standardDeviation << " STD2AvgRatio = " << standardDeviation / avgDeg << std::endl; 85 | 86 | std::cout << "totNbrs =" << totNbrs << " #links =" << input_graph.nb_links << std::endl; 87 | 88 | if (input_graph.nb_nodes < 10) { 89 | std::cout << std::endl; 90 | for (int i = 0; i < vtxDegs.size(); i++) { 91 | std::cout << vtxDegs[i] << " "; 92 | } 93 | std::cout << std::endl; 94 | } 95 | /**********************************/ 96 | 97 | //copy all edges 98 | g.links.resize(g.nb_links); 99 | g.links = input_graph.links; 100 | 101 | //copy all weights 102 | g.weights.resize(input_graph.weights.size()); 103 | g.weights = input_graph.weights; 104 | 105 | std::cout << std::endl << "Copied " << g.weights.size() << " weights" << std::endl; 106 | 107 | g.total_weight = input_graph.total_weight; 108 | 109 | 110 | if (input_graph.weights.size() > 0) { 111 | g.type = WEIGHTED; 112 | std::cout << " Setting type to WEIGHTED" << std::endl; 113 | } else { 114 | std::cout << "Type is already set to UNWEIGHTED" << std::endl; 115 | } 116 | 117 | //Community 118 | community_size = g.nb_nodes; 119 | min_modularity = min_mod; 120 | 121 | std::cout << std::endl << "(Dev Graph) " << " #Nodes: " << g.nb_nodes << " #Links: " << g.nb_links / 2 << " Total_Weight: " << g.total_weight / 2 << std::endl; 122 | std::cout << "community_size: " << community_size << std::endl; 123 | // seriously !! 124 | } 125 | -------------------------------------------------------------------------------- /FullSyncOptimization/fullSyncUtility.cpp: -------------------------------------------------------------------------------- 1 | #include "defs.h" 2 | #include "sync_comm.h" 3 | #include 4 | using namespace std; 5 | bool byVertexId(edge v1, edge v2){ 6 | return (v1.tail= fracFree) 31 | omp_set_lock(&vlocks[vtxInd[j].tail]); 32 | } 33 | 34 | 35 | // Aggregate the neighbors and lock their Community 36 | long sPosition = vtxPtr[v]+v; //Starting position of local map for v 37 | long storedAlready = 0; 38 | 39 | for(long j=adj1; j maxGain) || 93 | ((curGain==maxGain) && (curGain != 0) && (clusterLocalMap[sPosition + k].cid < maxIndex)) ) { 94 | maxGain = curGain; 95 | maxIndex = clusterLocalMap[sPosition + k].cid; 96 | } 97 | } 98 | }//End of for() 99 | 100 | if (sc != maxIndex){ 101 | if(ytype == 1){ 102 | CA[v] = maxIndex; 103 | cInfo[maxIndex].degree += vDegree[v]; 104 | cInfo[maxIndex].size += 1; 105 | cInfo[sc].degree -= vDegree[v]; 106 | cInfo[sc].size -=1; 107 | 108 | }else{ 109 | CA[v] = maxIndex; 110 | #pragma omp atomic update 111 | cInfo[maxIndex].degree += vDegree[v]; 112 | #pragma omp atomic update 113 | cInfo[maxIndex].size += 1; 114 | #pragma omp atomic update 115 | cInfo[sc].degree -= vDegree[v]; 116 | #pragma omp atomic update 117 | cInfo[sc].size -=1; 118 | } 119 | } 120 | 121 | if(ytype == 1){ 122 | // unLock all neighbors community 123 | for(long j=sPosition; jnumVertices; 51 | long NEdge = G->numEdges; 52 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 53 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 54 | 55 | 56 | // Rebuild indirection for coloring 57 | ColorVector colorPtr, colorIndex, freq; 58 | colorPtr.resize(ncolors+1); 59 | colorIndex.resize(NVer); 60 | freq.resize(ncolors); 61 | 62 | buildColorsIndex(vtxColor, ncolors, NVer, colorPtr, colorIndex, freq); 63 | 64 | BitVector overSize(ncolors,false); 65 | long avg = ceil(nv/ncolors); 66 | 67 | // Find the overSize bucket (can do some Optimization here) 68 | #pragma omp parallel for 69 | for(int ci = 0U; ci avg) 71 | overSize[ci]= true; 72 | } 73 | 74 | 75 | /* Begining of Redistribution */ 76 | std::cout <<"AVG:"<freq[ci]) 112 | myColor = ci; 113 | } 114 | 115 | //Update the color 116 | if(myColor != -1 && myColor < ncolors){ 117 | #pragma omp atomic update 118 | freq[myColor]++; 119 | #pragma omp atomic update 120 | freq[colors[v]]--; 121 | colors[v] = myColor; 122 | } 123 | }// End of singl color 124 | }//End of all colors. 125 | } //End of parallel step 126 | t2 = mytimer(); 127 | std::cout << outb << " CRE Time: " << t2-t1< 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include //For getopts() 59 | 60 | #define MilanRealMax HUGE_VAL // +INFINITY 61 | #define MilanRealMin -MilanRealMax // -INFINITY 62 | 63 | #define PRINT_DETAILED_STATS_ 64 | //#define PRINT_TERSE_STATS_ 65 | 66 | typedef struct comm 67 | { 68 | long size; 69 | double degree; 70 | }Comm; 71 | 72 | typedef struct 73 | { 74 | long cid; //community ID 75 | double Counter; //Weight relative to that community 76 | } mapElement; 77 | 78 | typedef struct /* the edge data structure */ 79 | { 80 | long head; 81 | long tail; 82 | double weight; 83 | } edge; 84 | 85 | typedef struct /* the graph data structure */ 86 | { 87 | long numVertices; /* Number of columns */ 88 | long sVertices; /* Number of rows: Bipartite graph: number of S vertices; T = N - S */ 89 | long numEdges; /* Each edge stored twice, but counted once */ 90 | long * edgeListPtrs; /* start vertex of edge, sorted, primary key */ 91 | edge * edgeList; /* end vertex of edge, sorted, secondary key */ 92 | } graph; 93 | 94 | typedef struct /* the graph data structure for directed graph */ 95 | { 96 | long numVertices; /* Number of vertices */ 97 | long numEdges; /* Each edge is stored only once (u --> v) */ 98 | //Outgoing edges 99 | long *edgeListPtrsOut; /* Edge pointer vector O(|V|) */ 100 | edge * edgeListOut; /* Edge weight vector O(|E|) */ 101 | //Incoming edges 102 | long *edgeListPtrsIn; /* Edge pointer vector O(|V|) */ 103 | edge * edgeListIn; /* Edge weight vector O(|E|) */ 104 | } dGraph; 105 | 106 | struct clustering_parameters 107 | { 108 | const char *inFile; //Input file 109 | int ftype; //File type 110 | 111 | bool strongScaling; //Enable strong scaling 112 | bool output; //Printout the clustering data 113 | bool VF; //Vertex following turned on 114 | int coloring; // Type of coloring 115 | bool replaceMap; //If map data structure is replaced with a vector 116 | int numColors; // Type of coloring 117 | int syncType; // Type of synchronization method 118 | int basicOpt; //If map data structure is replaced with a vector 119 | bool threadsOpt; 120 | double C_thresh; //Threshold with coloring on 121 | long minGraphSize; //Min |V| to enable coloring 122 | double threshold; //Value of threshold 123 | int percentage; 124 | bool compute_metrics; 125 | 126 | clustering_parameters(); 127 | void usage(); 128 | 129 | //Define in parseInputParameter.cpp 130 | bool parse(int argc, char *argv[]); 131 | }; 132 | 133 | //Reverse Cuthill-McKee Algorithm 134 | void algoReverseCuthillMcKee( graph *G, long *pOrder, int nThreads ); 135 | void algoReverseCuthillMcKeeStrict( graph *G, long *pOrder, int nThreads ); 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /driverForMatrixReorderingRcm.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | #include "basic_comm.h" 45 | #include "basic_util.h" 46 | #include "utilityClusteringFunctions.h" 47 | #include "color_comm.h" 48 | #include "sync_comm.h" 49 | 50 | using namespace std; 51 | //#define USEHDF5 52 | int main(int argc, char** argv) { 53 | 54 | //Parse Input parameters: 55 | clustering_parameters opts; 56 | if (!opts.parse(argc, argv)) { 57 | return -1; 58 | } 59 | int nT = 1; //Default is one thread 60 | #pragma omp parallel 61 | { 62 | nT = omp_get_num_threads(); 63 | } 64 | if (nT < 1) { 65 | printf("The number of threads should be greater than one.\n"); 66 | return 0; 67 | } 68 | 69 | // File Loading 70 | double time1, time2; 71 | graph* G = (graph *) malloc (sizeof(graph)); 72 | 73 | /* Step 2: Parse the graph in Matrix Market format */ 74 | int fType = opts.ftype; //File type 75 | char *inFile = (char*) opts.inFile; 76 | bool isSym = true; //Assume symmetric by default 77 | switch (fType) { 78 | case 1: isSym = parse_MatrixMarket(G, inFile); break; 79 | case 2: parse_Dimacs9FormatDirectedNewD(G, inFile); break; 80 | case 3: parse_PajekFormat(G, inFile); break; 81 | case 4: parse_PajekFormatUndirected(G, inFile); break; 82 | case 5: loadMetisFileFormat(G, inFile); break; 83 | case 6: //parse_UndirectedEdgeList(G, inFile); 84 | parse_UndirectedEdgeListDarpaHive(G, inFile); break; 85 | case 7: /* parse_DirectedEdgeList(G, inFile); break; */ 86 | printf("This routine is under development.\n"); exit(1); break; 87 | case 8: parse_SNAP(G, inFile); break; 88 | case 9: parse_EdgeListBinaryNew(G,inFile); break; 89 | case 10: 90 | #ifdef USEHDF5 91 | //parse_EdgeListCompressedHDF5(G,inFile); 92 | parse_EdgeListCompressedHDF5NoDuplicates(G,inFile); 93 | #endif 94 | break; 95 | default: cout<<"A valid file type has not been specified"<numVertices; 106 | long *old2NewMap = (long *) malloc (NV * sizeof(long)); assert(old2NewMap != 0); 107 | //Initialize the Vectors: 108 | #pragma omp parallel for 109 | for (long i=0; iedgeListPtrs); 129 | free(G->edgeList); 130 | free(G); 131 | } 132 | 133 | return 0; 134 | }//End of main() 135 | -------------------------------------------------------------------------------- /InputsOutput/loadDimacs.cpp: -------------------------------------------------------------------------------- 1 | #include "input_output.h" 2 | 3 | void parse_Dimacs9FormatDirectedNewD(graph * G, char *fileName) { 4 | printf("Parsing a DIMACS-9 formatted file as a general graph...\n"); 5 | printf("WARNING: Assumes that the graph is directed -- an edge is stored only once.\n"); 6 | printf(" : Graph will be stored as undirected, each edge appears twice.\n"); 7 | int nthreads = 0; 8 | #pragma omp parallel 9 | { 10 | nthreads = omp_get_num_threads(); 11 | } 12 | printf("parse_Dimacs9FormatDirectedNewD: Number of threads: %d\n ", nthreads); 13 | 14 | double time1, time2; 15 | FILE *file = fopen(fileName, "r"); 16 | if (file == NULL) { 17 | printf("Cannot open the input file: %s\n",fileName); 18 | exit(1); 19 | } 20 | char line[1024], LS1[25], LS2[25]; 21 | //Ignore the Comment lines starting with "c" 22 | do { 23 | fgets(line, 1024, file); 24 | } while ( line[0] == 'c'); 25 | //Expecting a problem line here: p sp n m 26 | long NV = 0, NE=0; 27 | //Parse the problem line: 28 | if(line[0] == 'p') { 29 | if (sscanf(line, "%s %s %ld %ld", LS1, LS2, &NV, &NE) != 4) { 30 | printf("parse_Dimacs9(): bad file format - 01"); 31 | exit(1); 32 | } 33 | } else { 34 | printf("parse_Dimacs9(): bad file format, expecting a line starting with p\n"); 35 | printf("%s\n", line); 36 | exit(1); 37 | } 38 | printf("|V|= %ld, |E|= %ld \n", NV, NE); 39 | printf("Weights will be converted to positive numbers.\n"); 40 | /*---------------------------------------------------------------------*/ 41 | /* Read edge list: a U V W */ 42 | /*---------------------------------------------------------------------*/ 43 | edge *tmpEdgeList = (edge *) malloc( NE * sizeof(edge)); //Every edge stored ONCE 44 | assert( tmpEdgeList != NULL); 45 | long Si, Ti; 46 | double Twt; 47 | time1 = omp_get_wtime(); 48 | for (long i = 0; i < NE; i++) { 49 | //Vertex lines: degree vlabel xcoord ycoord 50 | fscanf(file, "%s %ld %ld %lf", LS1, &Si, &Ti, &Twt); 51 | assert((Si > 0)&&(Si <= NV)); 52 | assert((Ti > 0)&&(Ti <= NV)); 53 | tmpEdgeList[i].head = Si-1; //The S index 54 | tmpEdgeList[i].tail = Ti-1; //The T index: One-based indexing 55 | tmpEdgeList[i].weight = fabs((double)Twt); //Make it positive and cast to Double 56 | }//End of outer for loop 57 | fclose(file); //Close the file 58 | time2 = omp_get_wtime(); 59 | printf("Done reading from file: NE= %ld. Time= %lf\n", NE, time2-time1); 60 | 61 | //Remove duplicate entries: 62 | /* long NewEdges = removeEdges(NV, NE, tmpEdgeList); 63 | if (NewEdges < NE) { 64 | printf("Number of duplicate entries detected: %ld\n", NE-NewEdges); 65 | NE = NewEdges; //Only look at clean edges 66 | } else { 67 | printf("No dubplicates found.\n"); 68 | }*/ 69 | /////////// 70 | time1 = omp_get_wtime(); 71 | long *edgeListPtr = (long *) malloc((NV+1) * sizeof(long)); 72 | assert(edgeListPtr != NULL); 73 | edge *edgeList = (edge *) malloc( 2*NE * sizeof(edge)); //Every edge stored twice 74 | assert( edgeList != NULL); 75 | time2 = omp_get_wtime(); 76 | printf("Time for allocating memory for storing graph = %lf\n", time2 - time1); 77 | #pragma omp parallel for 78 | for (long i=0; i <= NV; i++) 79 | edgeListPtr[i] = 0; //For first touch purposes 80 | 81 | //////Build the EdgeListPtr Array: Cumulative addition 82 | time1 = omp_get_wtime(); 83 | #pragma omp parallel for 84 | for(long i=0; isVertices = NV; 126 | G->numVertices = NV; 127 | G->numEdges = NE; 128 | G->edgeListPtrs = edgeListPtr; 129 | G->edgeList = edgeList; 130 | 131 | //Clean up 132 | free(tmpEdgeList); 133 | free(added); 134 | 135 | }//End of parse_Dimacs9FormatDirectedNewD() -------------------------------------------------------------------------------- /Coloring/vBase.cpp: -------------------------------------------------------------------------------- 1 | #include "coloringUtils.h" 2 | #include "defs.h" 3 | #include "coloring.h" 4 | 5 | /* The redistritbuted coloring step, no balance */ 6 | int vBaseRedistribution(graph* G, int* vtxColor, int ncolors, int type) 7 | { 8 | #ifdef PRINT_DETAILED_STATS_ 9 | printf("Vertex base redistribution\n"); 10 | #endif 11 | 12 | double time1=0, time2=0, totalTime=0; 13 | //Get the iterators for the graph: 14 | long NVer = G->numVertices; 15 | long NEdge = G->numEdges; 16 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 17 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 18 | 19 | #ifdef PRINT_DETAILED_STATS_ 20 | printf("Vertices: %ld Edges: %ld\n", NVer, NEdge); 21 | #endif 22 | 23 | //Build a vector of random numbers 24 | double *randValues = (double*) malloc (NVer * sizeof(double)); 25 | assert(randValues != 0); 26 | generateRandomNumbers(randValues, NVer); 27 | 28 | long *Q = (long *) malloc (NVer * sizeof(long)); assert(Q != 0); 29 | long *Qtmp = (long *) malloc (NVer * sizeof(long)); assert(Qtmp != 0); 30 | long *Qswap; 31 | if( (Q == NULL) || (Qtmp == NULL) ) { 32 | printf("Not enough memory to allocate for the two queues \n"); 33 | exit(1); 34 | } 35 | 36 | 37 | // initialize the color to baseColor 38 | int *baseColors = (int *) malloc (NVer * sizeof(int)); assert (baseColors != 0); 39 | #pragma omp parallel for 40 | for(long i = 0; i realMaxDegree) 64 | realMaxDegree = de; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////////////////// 68 | //////////////////////////// START THE WHILE LOOP /////////////////////////////////////// 69 | ///////////////////////////////////////////////////////////////////////////////////////// 70 | long nConflicts = 0; //Number of conflicts 71 | int nLoops = 0; //Number of rounds of conflict resolution 72 | 73 | // Holder for frequency, could use realMaxDegree here 74 | ColorVector freq(ncolors,0); 75 | BitVector overSize(ncolors,false); 76 | long avg = (long)ceil((double)NVer/(double)ncolors); 77 | 78 | // calculate the frequency 79 | computeBinSizes(freq,baseColors,NVer,ncolors); 80 | 81 | // Find the overSize bucket (can do some Optimization here) 82 | #pragma omp parallel for 83 | for(size_t ci = 0U; ci avg) 85 | overSize[ci]= true; 86 | 87 | /* Begining of Redistribution */ 88 | std::cout << "VR start "<< std::endl; 89 | 90 | 91 | // Coloring Main Loop 92 | do{ 93 | time1 = omp_get_wtime(); 94 | #pragma omp parallel for 95 | for (long Qi=0; Qifreq[ci]){ 120 | myColor = ci; 121 | } 122 | } 123 | } 124 | } 125 | 126 | if(vtxColor[v]==-1 && (myColor==-1 || myColor ==ncolors) ) 127 | myColor=baseColors[v]; 128 | 129 | if(myColor != ncolors && myColor !=-1){ 130 | #pragma omp atomic update 131 | freq[myColor]++; 132 | if(vtxColor[v] != -1){ 133 | #pragma omp atomic update 134 | freq[vtxColor[v]]--; 135 | } 136 | vtxColor[v] = myColor; 137 | } 138 | } // End of vertex wise redistribution 139 | 140 | time2 = omp_get_wtime(); 141 | 142 | #pragma omp parallel for 143 | for (long Qi=0; Qi 0); 165 | 166 | //Sanity check; 167 | distanceOneChecked(G,NVer,vtxColor); 168 | } 169 | 170 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | # Grappolo: Parallel clustering using the Louvain method as the serial template 2 | 3 | ## Description 4 | 5 | Grappolo implements a parallel version of the Louvain community detection algorithm, using several heuristics to gain computational speed. There can be a larger memory footprint and some loss of accuracy arising from non-deterministic order of vertex processing and use of different heuristics. In general, we have observed significant gains in speed with minimal impact on clustering accuracy (measure in terms of the final modularity score). Further, Grappolo enables processing of large inputs that would otherwise remain unsolved using the serial Louvain implementation. We also note that the distributed-memory version (Vite) is available for extremely large data sets. 6 | 7 | 8 | The single slice Grappolo has been divided to 7 folders 9 | 10 | /DefineStructure: Contain all .h files from different dirctories 11 | /Utility: check basic_ultil.h and utilityClusteringFunc.h 12 | /BasicCommunitiesDection: check basic_comm.h 13 | /Coloring: check coloring.h and comm_coloring.h 14 | /FullSyncOptimization: check sync_comm.h 15 | /InputsOutput: check input_output.h 16 | 17 | 18 | /****************************************************/ 19 | Makefile will create 3 executable in the /bin folder 20 | 1) ./convertFileToBinary 21 | 2) ./driverForGraphClustering 22 | 3) ./driverForColoring 23 | 24 | 25 | 26 | /****************************************************/ 27 | To update code, record each update in the folder. 28 | To updates for each particular type of communities detection 29 | 30 | 1) Change code in particualr folder 31 | / Add different communities detection method 32 | 33 | 2) Change the runMultiPhaseXXX.cpp to capture the changes 34 | 35 | 3) Update the .h files in /DefineStructure 36 | 37 | 4) Drivers and other folder can remain unchanged 38 | 39 | 5) To update the Utility code must be done with care, API should 40 | stay the same 41 | 42 | /****************************************************/ 43 | To run the code, it will be in the menu of ./driverForGraphClustering 44 | 45 | 46 | 47 | 48 | 49 | ## Input parameters that can be customized: 50 | 51 | `links` A numeric matrix of network edges. 52 | 53 | `coloring` (1) An integer between 0 and 3 that controls the distance-1 graph coloring heuristic used to partition independent sets of vertices in a graph for parallel processing. 54 | * 0 - No coloring. 55 | * 1 - (Default) Distance-1 graph coloring. Every vertex receives a color and no two neighbors have the same color. 56 | * 2 – Distance-1 graph coloring, rebalanced for evenly distributed color classes (#nodes per color). 57 | * 3 - Incomplete coloring, limited to `numColors`, by default 16. 58 | 59 | `numColors` (16): An integer between 1 and 1024. Limits graph coloring. Only used if `coloring=3`, incomplete coloring, is set. 60 | 61 | `C_thresh` (1e-6): The threshold value determines how long the algorithm iterates. This value (a real number between 0 and 1; >0) is checked when coloring is enabled. The algorithm will stop iterating when the gain in modularity becomes less than `C_thresh`. A final iteration is performed using the value specified by the `threshold` parameter. Desired value for `C_thresh` should be larger than `threshold` for gains in performance. 62 | 63 | `minGraphSize` (1,000): Determines when multi-phase operations should stop. Execution stops when the coarsened graph has collapsed the current graph to a fewer than `minGraphSize` nodes. 64 | 65 | `threshold` (1e-9): The threshold value determines how long the algorithm iterates. It is a real number between 0 and 1 (>0). The algorithm will stop the iterations in the current phase when the gain in modularity is less than `threshold`. The algorithm can enter the next phase based on the size of the coarsened graph. 66 | 67 | `syncType` (0) An integer between 0 and 4 that controls synchronization between threads. Only applies if `coloring=0` (no coloring). Synchronization forces the parallel algorithm to behave similar to the execution of a serial Louvain implementation. 68 | * 0 - (Default) No sync (gives the best performance in terms of runtime). 69 | * 1 - Full sync (behaves like a serial algorithm). 70 | * 2 - Neighborhood sync (a hybrid between 0 and 1). 71 | * 3 - Early termination (stops processing a vertex if it has not changed its community for the past few iterations – leads to gain in performance). 72 | * 4 - Full sync with early termination (hybrid of 1 and 3). 73 | 74 | `basicOpt` (1) Either 0 or 1, controls the representation of intermediate data structures. 75 | * 0 – Uses stl::map data structure. While it has a smaller memory footprint and computational efficiency, excessive memory allocations and deallocations can lead to loss of performance. 76 | * 1 - (Default) Use stl::vector to replace the functionality of stl::map. This option comes at the expense of a larger memory footprint and loss in performance when the algorithm has a large number of communities and does not converge quickly (does not have a good community structure). In general, this option can be faster than the stl::map option for inputs with good community structure. 77 | 78 | 79 | ## Further Details: 80 | 81 | The only required parameter is `links`. All other parameters are tuning parameters that control how speed vs accuracy vs memory tradeoffs are made. We specifically note that the original Louvain algorithm is non-deterministic and varies considerably for different input structures. Grappolo inherits these limitations with added complications from parallelization. 82 | 83 | ## Return Value: 84 | 85 | A list with two elements: 86 | 87 | * `modularity` - The modularity of the computed partitioning of the network into a set of non-overlapping clusters (communities or partitions). Modularity is a measure of the connectedness in a given network when partitioned based on a given approach. 88 | * `communities` - A vector where the i'th value is the cluster number that the i'th node in the links matrix has been assigned to. 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /bColoring/bBase.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "coloringUtils.h" 43 | //extern GraphElem MaxDegree; 44 | /* The redistritbuted coloring step, no balance */ 45 | ColorElem schRedistribution(const Graph &g, ColorVector &colors, std::string input, ColorElem ncolors) 46 | { 47 | double t1,t2; 48 | t1 = mytimer(); 49 | const GraphElem nv = g.getNumVertices(); 50 | RandVec randVec(nv); 51 | generateRandomNumbers(randVec); 52 | 53 | srand(time(NULL)); 54 | std::string outb; 55 | outb = input+".SeR"; 56 | 57 | // Rebuild indirection for coloring 58 | ColorVector colorPtr, colorIndex, freq; 59 | colorPtr.resize(ncolors+1); 60 | colorIndex.resize(nv); 61 | freq.resize(ncolors); 62 | buildColorsIndex(colors,ncolors,nv,colorPtr,colorIndex,freq); 63 | GraphElem avg = ceil(nv/ncolors); 64 | 65 | 66 | // MultiTries variable 67 | int shift = 0; 68 | int nmoved = 0; 69 | // Conflicts check statistics 70 | ColorElem nconflicts=0; 71 | int nloops = 0; 72 | GraphElem realMaxDegree = -1; 73 | 74 | 75 | /* Begining of Redistribution */ 76 | std::cout << "BatchMove start "<< std::endl; 77 | 78 | 79 | // Coloring Main Loop 80 | do{ 81 | //Build the move queue 82 | MoveQueue marray; 83 | ColorVector newFreq=freq; 84 | for(ColorElem ci = 0; ci avg){ //Visit all other colors if overSize 88 | for(ColorElem ti= (ncolors-1-shift)%ncolors; counter 31 | 32 | /* 33 | const int MAX_SIZE = 1600; 34 | typedef struct 35 | { 36 | int maxsize = MAX_SIZE; // Maximum size 37 | int size; // Current size 38 | term * elements; // vector of elements 39 | } heap; 40 | */ 41 | 42 | //Initialize the heap data structure to size HEAP_MAX_SIZE 43 | void heapInitialize(heap *myHeap) { 44 | myHeap->maxsize = HEAP_MAX_SIZE; 45 | myHeap->size = 0; 46 | term* data = (term *) malloc (HEAP_MAX_SIZE * sizeof(term)); 47 | myHeap->elements = data; 48 | } 49 | 50 | void heapInitializeToN(heap *myHeap, long n) { 51 | myHeap->maxsize = n+1; 52 | myHeap->size = 0; 53 | term* data = (term *) malloc (n * sizeof(term)); 54 | myHeap->elements = data; 55 | } 56 | 57 | //Add an element to the heap: 58 | void heapAdd(heap *myHeap, term t1) { 59 | if (myHeap->size < (myHeap->maxsize-1)) { 60 | //myHeap->size++; //Increment the size 61 | //Start from the last position and move up to the correct location 62 | long position = myHeap->size++; 63 | term *data = myHeap->elements; 64 | while ( (position > 0)&&(t1.weightelements; 78 | //First move the last element into the first position: 79 | if ( myHeap->size > 0 ){ 80 | data[0].id = data[myHeap->size-1].id; 81 | data[0].weight = data[myHeap->size-1].weight; 82 | myHeap->size--; //Decrement the size to reflect the deletion 83 | } else { 84 | printf("Within heapRemoveMin(): Heap is empty\n"); 85 | } 86 | //Rebuild the heap only if it is still not empty 87 | if ( myHeap->size > 0 ){ 88 | long position = 0; 89 | term value; 90 | value.id = data[position].id; 91 | value.weight = data[position].weight; 92 | 93 | while ( position < myHeap->size ){ 94 | //Replace position with the smaller of the two children 95 | //replace with the last element, otherwise 96 | long childPosition = position*2 + 1; 97 | if ( childPosition < myHeap->size ){ 98 | if ( (childPosition+1 < myHeap->size) && 99 | (data[childPosition+1].weight < data[childPosition].weight) ) { 100 | childPosition += 1; 101 | } 102 | //childPosition is smaller of the two children: 103 | if ( value.weight < data[childPosition].weight ) { 104 | //Found the right location: 105 | data[position].id = value.id; 106 | data[position].weight = value.weight; 107 | break; 108 | } 109 | else { 110 | data[position].id = data[childPosition].id; 111 | data[position].weight = data[childPosition].weight; 112 | position = childPosition; 113 | //recur and keep moving down 114 | } 115 | } 116 | else { //No children exist 117 | data[position].id = value.id; 118 | data[position].weight = value.weight; 119 | break; 120 | } 121 | }//End of while() 122 | }//End of if() 123 | }//End of heapRemoveMin 124 | 125 | -------------------------------------------------------------------------------- /driverForColoring.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "coloring.h" 44 | #include "input_output.h" 45 | #include "basic_util.h" 46 | int main(int argc, char** argv) { 47 | 48 | //Parse Input parameters: 49 | clustering_parameters opts; 50 | if (!opts.parse(argc, argv)) { 51 | return -1; 52 | } 53 | int nT = 1; //Default is one thread 54 | #pragma omp parallel 55 | { 56 | nT = omp_get_num_threads(); 57 | } 58 | if (nT <= 1) { 59 | printf("The number of threads should be greater than one.\n"); 60 | return 0; 61 | } 62 | graph* G = (graph *) malloc (sizeof(graph)); 63 | 64 | int fType = opts.ftype; //File type 65 | char *inFile = (char*) opts.inFile; 66 | 67 | if(fType == 1) 68 | parse_MatrixMarket_Sym_AsGraph(G, inFile); 69 | else if(fType == 2) 70 | parse_Dimacs9FormatDirectedNewD(G, inFile); 71 | else if(fType == 3) 72 | parse_PajekFormat(G, inFile); 73 | else if(fType == 4) 74 | parse_PajekFormatUndirected(G, inFile); 75 | else if(fType == 5) 76 | loadMetisFileFormat(G, inFile); 77 | else if(fType == 6) 78 | parse_UndirectedEdgeList(G, inFile); 79 | else if(fType == 7) 80 | parse_DirectedEdgeList(G, inFile); 81 | else if(fType == 8) 82 | parse_SNAP(G, inFile); 83 | else if(fType == 9) 84 | parse_EdgeListBinaryNew(G,inFile); 85 | else { 86 | cout<<"Not a valid file type"<numVertices * sizeof(int)); assert (colors != 0); 99 | 100 | #pragma omp parallel for 101 | for (long i=0; inumVertices; i++) { 102 | colors[i] = -1; 103 | } 104 | double tmpTime; 105 | //numColors = algoDistanceOneVertexColoringOpt(G, colors, nT, &tmpTime); 106 | numColors = algoColoringMultiHashMaxMin(G, colors, 1, &tmpTime, opts.syncType, opts.coloring); 107 | 108 | printf("Time to color: %lf\n", tmpTime); 109 | //return 0; 110 | 111 | /* Step : Set up output parameters */ 112 | /* char buf1[256]; 113 | sprintf(buf1,"%s_colorFreq.txt",argv[1]); 114 | FILE* out1 = fopen(buf1,"w"); 115 | char buf2[256]; 116 | sprintf(buf2,"%s_colorTiming.txt",argv[1]); 117 | FILE* out2 = fopen(buf2,"w"); 118 | */ 119 | 120 | printf("What is this %s\n",argv[1]); 121 | /* 122 | int curThread = 2; //Start with two threads 123 | while (curThread <= nT) { 124 | printf("\n\n***************************************\n"); 125 | printf("Starting run with %d threads.\n", curThread); 126 | printf("***************************************\n"); 127 | fprintf(out2, "*******************************\n"); 128 | fprintf(out2, "Number of threads: %d\n",curThread); 129 | fprintf(out2, "*******************************\n"); 130 | 131 | #pragma omp parallel for 132 | for (long i=0; inumVertices; i++) { 133 | colors[i] = -1; 134 | } 135 | numColors = algoDistanceOneVertexColoringOpt(G, colors, curThread, &tmpTime); 136 | fprintf(out2, "Time to color : %lf\n",tmpTime); 137 | 138 | curThread = curThread*2; 139 | }//End of while() 140 | */ 141 | //Count the frequency of colors: 142 | long *colorFreq = (long *) malloc (numColors * sizeof(long)); assert(colorFreq != 0); 143 | #pragma omp parallel for 144 | for(long i = 0; i < numColors; i++) { 145 | colorFreq[i] = 0; 146 | } 147 | 148 | #pragma omp parallel for 149 | for(long i = 0; i < G->numVertices; i++) { 150 | __sync_fetch_and_add(&colorFreq[colors[i]],1); 151 | } 152 | 153 | for(long i=0; i < numColors; i++) { 154 | printf("%ld \t %ld\n", i, colorFreq[i]); 155 | } 156 | 157 | /* Step 5: Clean up */ 158 | free(G->edgeListPtrs); 159 | free(G->edgeList); 160 | free(G); 161 | 162 | free(colorFreq); 163 | free(colors); 164 | 165 | return 0; 166 | 167 | } 168 | -------------------------------------------------------------------------------- /gpu_graph/preprocessing.cu: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Rundemanen: CUDA C++ parallel program for community detection 4 | // Md Naim (naim.md@gmail.com), Fredrik Manne (Fredrik.Manne@uib.no) 5 | // University of Bergen 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2016) University of Bergen 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include 43 | #include 44 | #include "communityGPU.h" 45 | #include"hostconstants.h" 46 | 47 | void Community::preProcess() { 48 | 49 | 50 | 51 | //Compute degree of each node 52 | thrust::device_vector sizesOfNhoods(g.indices.size() - 1, 0); 53 | 54 | 55 | thrust::transform(g.indices.begin() + 1, g.indices.end(), g.indices.begin(), 56 | sizesOfNhoods.begin(), thrust::minus()); 57 | 58 | //Find all degree 1 vertices 59 | IsInRange filter_SNL_1(1, 1); 60 | 61 | int nrC_SNL_1 = thrust::count_if(thrust::device, sizesOfNhoods.begin(), 62 | sizesOfNhoods.end(), filter_SNL_1); 63 | 64 | std::cout << "#vertices (SNL=1):" << nrC_SNL_1 << std::endl; 65 | 66 | //Lets copy Identities of all communities in g_next.links 67 | 68 | g_next.links.resize(community_size, 0); 69 | thrust::sequence(g_next.links.begin(), g_next.links.end(), 0); 70 | 71 | //Use g_next.indices to copy community ids with SLN =1 72 | g_next.indices.resize(community_size, -1); 73 | 74 | 75 | //Collet all degree 1 vertices in g_next.indices 76 | thrust::copy_if(thrust::device, g_next.links.begin(), g_next.links.end(), 77 | sizesOfNhoods.begin(), g_next.indices.begin(), filter_SNL_1); 78 | 79 | 80 | 81 | /* 82 | void reduceGraph(int* indices, unsigned int* links, float* weights, int gType, 83 | int* uniDegvrts, unsigned int nrUniDegVrts, unsigned int mark, 84 | int* vtsForPostProcessing); 85 | */ 86 | 87 | 88 | int mark = g.nb_nodes * 2; 89 | thrust::device_vector vtsForPostProcessing(nrC_SNL_1, -1); 90 | 91 | unsigned int nrBlk = (nrC_SNL_1 + NR_THREAD_PER_BLOCK - 1) / NR_THREAD_PER_BLOCK; 92 | 93 | //initialization of n2c 94 | n2c.resize(community_size); 95 | thrust::sequence(n2c.begin(), n2c.end(), 0); 96 | if(nrC_SNL_1>0) 97 | reduceGraph << >>( 98 | thrust::raw_pointer_cast(g.indices.data()), 99 | thrust::raw_pointer_cast(g.links.data()), 100 | thrust::raw_pointer_cast(g.weights.data()), g.type, 101 | thrust::raw_pointer_cast(g_next.indices.data()), nrC_SNL_1, mark, 102 | thrust::raw_pointer_cast(vtsForPostProcessing.data()), 103 | thrust::raw_pointer_cast(n2c.data())); 104 | 105 | /* 106 | // let's process each vertex in vtsForPostProcessing with a warp 107 | nrBlk = (nrC_SNL_1 + (NR_THREAD_PER_BLOCK / PHY_WRP_SZ) - 1) / (NR_THREAD_PER_BLOCK / PHY_WRP_SZ); 108 | 109 | void editEdgeList(int* indices, unsigned int* links, float* weights, int gType, 110 | int* uniDegvrts, unsigned int nrUniDegVrts, unsigned int mark, 111 | int* vtsForPostProcessing); 112 | 113 | editEdgeList << >>( 114 | thrust::raw_pointer_cast(g.indices.data()), 115 | thrust::raw_pointer_cast(g.links.data()), 116 | thrust::raw_pointer_cast(g.weights.data()), g.type, 117 | thrust::raw_pointer_cast(g_next.indices.data()), nrC_SNL_1, mark, 118 | thrust::raw_pointer_cast(vtsForPostProcessing.data())); 119 | */ 120 | 121 | 122 | if (0) { 123 | thrust::host_vector uniDegVertices = g_next.indices; 124 | std::cout << std::endl; 125 | for (int i = 0; i < nrC_SNL_1; i++) { 126 | std::cout << uniDegVertices[i] << " "; 127 | } 128 | std::cout << std::endl; 129 | } 130 | 131 | if (0) { 132 | thrust::host_vector gnlinks = g.links; 133 | thrust::host_vector gnIndices = g.indices; 134 | thrust::device_vector gnWeights = g.weights; 135 | for (unsigned int i = 0; i < g.nb_nodes; i++) { 136 | 137 | unsigned int startNbr = gnIndices[i]; 138 | unsigned int endNbr = gnIndices[i + 1]; 139 | //thrust::sort(gnlinks.begin() + startNbr, gnlinks.begin() + endNbr); 140 | 141 | if(i<10){ 142 | std::cout << i << ":"; 143 | 144 | for (unsigned int j = startNbr; j < endNbr; j++) { 145 | 146 | float edgeWt = 1; 147 | if (g.type == WEIGHTED) 148 | edgeWt = gnWeights[j]; 149 | std::cout << " " << gnlinks[j] << "(" << edgeWt << ")"; 150 | } 151 | std::cout << std::endl; 152 | } 153 | } 154 | } 155 | 156 | n2c.clear(); 157 | vtsForPostProcessing.clear(); 158 | sizesOfNhoods.clear(); 159 | g_next.links.clear(); 160 | g_next.indices.clear(); 161 | 162 | } 163 | -------------------------------------------------------------------------------- /InputsOutput/writeMatrixMarket.cpp: -------------------------------------------------------------------------------- 1 | #include "input_output.h" 2 | void writeGraphMatrixMarketFormatSymmetric(graph* G, char *filename) { 3 | //Get the iterators for the graph: 4 | long NVer = G->numVertices; 5 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 6 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 7 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 8 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 9 | 10 | printf("Writing graph in Matrix Market (symmetric) format - each edge represented ONLY ONCE!\n"); 11 | printf("Matrix will be stored in file: %s\n", filename); 12 | 13 | FILE *fout; 14 | fout = fopen(filename, "w"); 15 | if (!fout) { 16 | printf("Could not open the file \n"); 17 | exit(1); 18 | } 19 | //First Line: Header for Matrix Market: 20 | fprintf(fout, "\%\%MatrixMarket matrix coordinate real symmetric\n"); 21 | fprintf(fout, "\%=================================================================================\n"); 22 | fprintf(fout, "\% Indices are 1-based, i.e. A(1,1) is the first element.\n"); 23 | fprintf(fout, "\% Can contain self-loops (diagonal entries)\n"); 24 | fprintf(fout, "\% Number of edges might not match with actual edges (nonzeros).\n"); 25 | fprintf(fout, "\%=================================================================================\n"); 26 | fprintf(fout, "%ld %ld %ld\n", NVer, NVer, NEdge); 27 | 28 | //Write the edges (lower triangle only): 29 | for (long v=0; v 33 | for(long k = adj1; k < adj2; k++ ) { 34 | if (verInd[k].tail <= v ) { //Print only once (lower triangle) 35 | fprintf(fout, "%ld %ld %g\n", v+1, (verInd[k].tail+1), (verInd[k].weight) ); 36 | } 37 | } 38 | } 39 | fclose(fout); 40 | printf("Matrix has been stored in file: %s\n",filename); 41 | }//End of writeGraphPajekFormat() 42 | 43 | 44 | //This routine outputs the graph as a "reordered" symmetric matrix 45 | //The vector old2NewMap contains the new ids for old ids 46 | void writeGraphMatrixMarketFormatSymmetricReordered(graph* G, char *filename, long *old2NewMap) { 47 | printf("Within writeGraphMatrixMarketFormatSymmetricReordered()\n"); 48 | //Get the iterators for the graph: 49 | long NVer = G->numVertices; 50 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 51 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 52 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 53 | printf("NVer= %ld -- NE=%ld\n", NVer, NEdge); 54 | 55 | printf("Writing graph in Matrix Market (symmetric) format - each edge represented ONLY ONCE!\n"); 56 | printf("Matrix will be stored in file: %s\n", filename); 57 | 58 | FILE *fout; 59 | fout = fopen(filename, "w"); 60 | if (!fout) { 61 | printf("Could not open the file \n"); 62 | exit(1); 63 | } 64 | //First Line: Header for Matrix Market: 65 | fprintf(fout, "\%\%\%\%MatrixMarket matrix coordinate real symmetric\n"); 66 | fprintf(fout, "\%\%=================================================================================\n"); 67 | fprintf(fout, "\%\% Indices are 1-based, i.e. A(1,1) is the first element.\n"); 68 | fprintf(fout, "\%\% Can contain self-loops (diagonal entries)\n"); 69 | fprintf(fout, "\%\% Number of edges might not match with actual edges (nonzeros).\n"); 70 | fprintf(fout, "\%\%=================================================================================\n"); 71 | fprintf(fout, "%ld %ld %ld\n", NVer, NVer, NEdge); 72 | 73 | //Write the edges 74 | for (long v=0; v 78 | for(long k = adj1; k < adj2; k++ ) { 79 | if (verInd[k].tail <= v ) { //Print only once (lower triangle) 80 | fprintf(fout, "%ld %ld %g\n", old2NewMap[v]+1, (old2NewMap[verInd[k].tail]+1), (verInd[k].weight) ); 81 | } 82 | } 83 | } 84 | fclose(fout); 85 | printf("Matrix has been stored in file: %s\n",filename); 86 | }//End of writeGraphPajekFormat() 87 | 88 | //This routine outputs the graph as a "reordered" symmetric matrix 89 | //The vector old2NewMap contains the new ids for old ids 90 | void writeGraphMatrixMarketFormatBipartiteReordered(graph* G, char *filename, long *old2NewMap) { 91 | printf("Within writeGraphMatrixMarketFormatBipartiteReordered()\n"); 92 | //Get the iterators for the graph: 93 | long NVer = G->numVertices; 94 | long NS = G->sVertices; 95 | long NT = NVer - NS; assert(NT > 0); //Make sure that the graph is bipartite 96 | long NEdge = G->numEdges; //Returns the correct number of edges (not twice) 97 | long *verPtr = G->edgeListPtrs; //Vertex Pointer: pointers to endV 98 | edge *verInd = G->edgeList; //Vertex Index: destination id of an edge (src -> dest) 99 | printf("NS= %ld -- NT= %ld -- NE=%ld\n", NS, NT, NEdge); 100 | 101 | printf("Writing graph in Matrix Market (unsymmetric) format - each edge represented ONCE!\n"); 102 | printf("Matrix will be stored in file: %s\n", filename); 103 | 104 | FILE *fout; 105 | fout = fopen(filename, "w"); 106 | if (!fout) { 107 | printf("Could not open the file \n"); 108 | exit(1); 109 | } 110 | 111 | //First Line: Header for Matrix Market: 112 | fprintf(fout, "\%\%\%\%MatrixMarket matrix coordinate real general\n"); 113 | fprintf(fout, "\%\%=================================================================================\n"); 114 | fprintf(fout, "\%\% Indices are 1-based, i.e. A(1,1) is the first element.\n"); 115 | fprintf(fout, "\%\% Edges (nonzeros) appear only once.\n"); 116 | fprintf(fout, "\%\%=================================================================================\n"); 117 | fprintf(fout, "%ld %ld %ld\n", NS, NT, NEdge); 118 | //Write the edges (Only from the row perspective): 119 | for (long v=0; v 123 | for(long k = adj1; k < adj2; k++ ) { 124 | fprintf(fout, "%ld %ld %g\n", old2NewMap[v]+1, old2NewMap[verInd[k].tail]-NS+1, verInd[k].weight ); 125 | }//End of for(k) 126 | }//End of for(v) 127 | fclose(fout); 128 | printf("Matrix has been stored in file: %s\n",filename); 129 | }//End of writeGraphPajekFormat() 130 | 131 | -------------------------------------------------------------------------------- /driverForMatrixReorderingND.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "defs.h" 43 | #include "input_output.h" 44 | #include "basic_comm.h" 45 | #include "basic_util.h" 46 | #include "utilityClusteringFunctions.h" 47 | #include "color_comm.h" 48 | #include "sync_comm.h" 49 | #include "utilityNestedDisectionMetis.h" 50 | 51 | using namespace std; 52 | //#define USEHDF5 53 | int main(int argc, char** argv) { 54 | 55 | //Parse Input parameters: 56 | clustering_parameters opts; 57 | if (!opts.parse(argc, argv)) { 58 | return -1; 59 | } 60 | int nT = 1; //Default is one thread 61 | #pragma omp parallel 62 | { 63 | nT = omp_get_num_threads(); 64 | } 65 | if (nT < 1) { 66 | printf("The number of threads should be greater than one.\n"); 67 | return 0; 68 | } 69 | 70 | // File Loading 71 | double time1, time2; 72 | graph* G = (graph *) malloc (sizeof(graph)); 73 | 74 | /* Step 2: Parse the graph in Matrix Market format */ 75 | int fType = opts.ftype; //File type 76 | char *inFile = (char*) opts.inFile; 77 | bool isSym = true; //Assume symmetric by default 78 | switch (fType) { 79 | case 1: isSym = parse_MatrixMarket(G, inFile); break; 80 | case 2: parse_Dimacs9FormatDirectedNewD(G, inFile); break; 81 | case 3: parse_PajekFormat(G, inFile); break; 82 | case 4: parse_PajekFormatUndirected(G, inFile); break; 83 | case 5: loadMetisFileFormat(G, inFile); break; 84 | case 6: //parse_UndirectedEdgeList(G, inFile); 85 | parse_UndirectedEdgeListDarpaHive(G, inFile); break; 86 | case 7: parse_DirectedEdgeList(G, inFile); break; 87 | case 8: parse_SNAP(G, inFile); break; 88 | case 9: parse_EdgeListBinaryNew(G,inFile); break; 89 | case 10: 90 | #ifdef USEHDF5 91 | //parse_EdgeListCompressedHDF5(G,inFile); 92 | parse_EdgeListCompressedHDF5NoDuplicates(G,inFile); 93 | #endif 94 | break; 95 | default: cout<<"A valid file type has not been specified"<numVertices; 106 | long NS = G->sVertices; 107 | long NT = NV - NS; 108 | long *old2NewMap = (long *) malloc (NV * sizeof(long)); assert(old2NewMap != 0); 109 | //Initialize the Vectors: 110 | #pragma omp parallel for 111 | for (long i=0; i 0); 133 | long rowCounter = 0; 134 | long colCounter = NS; 135 | long *Rprime = (long *) malloc (NV * sizeof(long)); assert(Rprime != 0); 136 | for (long i=0; i=0; i--) { //Go through the list in a reverse order 140 | if(old2NewMap[i] < NS) { //A row vertex 141 | Rprime[rowCounter] = old2NewMap[i]; 142 | rowCounter++; 143 | } else { //A column vertex 144 | Rprime[colCounter] = old2NewMap[i]; 145 | colCounter++; 146 | } 147 | }//End of for(i) 148 | assert(rowCounter==NS); assert(colCounter==NV); //Sanity check 149 | //STEP 3.2: Now build the old2New map: 150 | for (long i=0; iedgeListPtrs); 163 | free(G->edgeList); 164 | free(G); 165 | } 166 | 167 | return 0; 168 | }//End of main() 169 | -------------------------------------------------------------------------------- /bColoring/initialColoringLU.cpp: -------------------------------------------------------------------------------- 1 | // *********************************************************************** 2 | // 3 | // Grappolo: A C++ library for graph clustering 4 | // Mahantesh Halappanavar (hala@pnnl.gov) 5 | // Pacific Northwest National Laboratory 6 | // 7 | // *********************************************************************** 8 | // 9 | // Copyright (2014) Battelle Memorial Institute 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // 3. Neither the name of the copyright holder nor the names of its 24 | // contributors may be used to endorse or promote products derived from 25 | // this software without specific prior written permission. 26 | // 27 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | // POSSIBILITY OF SUCH DAMAGE. 39 | // 40 | // ************************************************************************ 41 | 42 | #include "coloringUtils.h" 43 | //extern GraphElem MaxDegree; 44 | /* The basic coloring step, no balance */ 45 | ColorElem initColoringLU(const Graph &g, ColorVector &colors, std::string input) 46 | { 47 | std::cout << "WELCOME TO THE LEAST USED ABI SHCHEM" < outPutName(3); 58 | outPutName[0] = input+".DefaultD"; 59 | outPutName[1] = input+".ALeastUsedD"; 60 | outPutName[2] = input+".ARandomD"; 61 | 62 | // initialize the color to -1 63 | colors.resize(nv); 64 | #pragma omp parallel for default(none), shared(colors), schedule(static) 65 | for (GraphElem i = 0L; i < nv; i++) 66 | colors[i] = -1; 67 | 68 | // Set up all vertices in the queue 69 | ColorQueue q(nv), qtmp; 70 | GraphElem qtmpPos = 0L; 71 | #pragma omp parallel for default(none), shared(q), schedule(static) 72 | for (GraphElem i = 0; i < nv; i++) 73 | q[i] = i; 74 | ColorElem nconflicts = 0; 75 | int nloops = 0; 76 | GraphElem realMaxDegree = -1L; 77 | 78 | // Cal real maximum degree, not sure where it is used 79 | #pragma omp parallel for default(none), shared(g), reduction(max: realMaxDegree), schedule(static) 80 | for (GraphElem i = 0L; i < nv; i++) { 81 | GraphElem e0, e1, er; 82 | g.getEdgeRangeForVertex(i, e0, e1); 83 | er = e1 - e0; 84 | if (er > realMaxDegree) 85 | realMaxDegree = er; 86 | } 87 | static_assert(sizeof(int) == sizeof(int32_t), "int should be 32-bit in size"); 88 | assert((realMaxDegree < INT32_MAX) && (realMaxDegree > 0L)); 89 | 90 | // std::cout << "Maximum degree for the graph: " << realMaxDegree << std::endl; 91 | 92 | // Because we do not know how much does the color really is 93 | ColorVector freq(MaxDegree,0); 94 | 95 | do { 96 | size_t qsz = q.size(); 97 | qtmp.resize(qsz); 98 | double mst=0, cst=0; 99 | #pragma omp parallel default(none), shared(freq,q, qtmp, qtmpPos, randVec, g, colors, qsz, nloops, nconflicts, std::cerr) 100 | { 101 | // Coloring step 102 | #pragma omp for firstprivate(nloops, qsz), schedule(guided) 103 | for (GraphElem qi = 0L; qi < qsz; qi++) { 104 | GraphElem v = q[qi]; 105 | ColorElem maxColor = -1; 106 | BitVector mark(MaxDegree, false); 107 | 108 | // Mark the array 109 | maxColor = distanceOneMarkArray(mark, g, v, colors); 110 | ColorElem myColor = -1; 111 | ColorElem target ; 112 | ColorElem permissable = 0; 113 | 114 | // Pick the target 115 | // Assefaw least used 116 | for(target = 0; target freq[target]) 120 | myColor = target; 121 | } 122 | if(myColor == -1) 123 | myColor = target; 124 | 125 | #pragma omp atomic update 126 | freq[myColor]++; 127 | colors[v] = myColor; 128 | }// End of coloring 129 | 130 | //Conflicts resloution step 131 | #pragma omp for firstprivate(qsz), schedule(guided) 132 | for (GraphElem qi = 0L; qi < qsz; qi++) { 133 | GraphElem v = q[qi]; 134 | distanceOneConfResolution(g,v,colors,freq,randVec,qtmp,qtmpPos,1); 135 | } //End of identify all conflicts (re-set conflicts to -1) 136 | #pragma omp single 137 | { 138 | q.resize(qtmpPos); 139 | } 140 | #pragma omp for schedule(static) 141 | for (GraphElem qi = 0; qi ncolors) 164 | ncolors = colors[ci]; 165 | } 166 | std::cout<<"Total Number of Colors used: " << ncolors<dMax) 178 | dMax = xP; 179 | } 180 | std::cout<< "Max Degree: " << dMax <