├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── LICENSE ├── README.md ├── clean_cmake.sh ├── new_build.txt ├── rebuild.sh ├── run_tests.sh ├── run_tests2.sh ├── src ├── CMakeLists.txt ├── Doxyfile ├── algorithms │ ├── algorithms.hpp │ ├── appendix_algorithms.hpp │ ├── apsp.hpp │ ├── bc.hpp │ ├── bfs.hpp │ ├── cluster.hpp │ ├── cluster_louvain.hpp │ ├── k_truss.hpp │ ├── maxflow.hpp │ ├── metrics.hpp │ ├── mis.hpp │ ├── mst.hpp │ ├── page_rank.hpp │ ├── sssp.hpp │ └── triangle_count.hpp ├── demo │ ├── .gitignore │ ├── Timer.hpp │ ├── appendix_examples.cpp │ ├── bfs_demo.cpp │ ├── bfs_level_demo.cpp │ ├── ewise_mult_timing_demo.cpp │ ├── k_truss_data.tsv │ ├── k_truss_demo.cpp │ ├── louvain_demo.cpp │ ├── louvain_karate_demo.cpp │ ├── masked_mxm_homework.cpp │ ├── mxm_homework.cpp │ ├── mxm_timing_demo.cpp │ ├── mxv_timing_demo.cpp │ ├── peer_pressure_demo.cpp │ ├── peer_pressure_karate_demo.cpp │ ├── simulated_blockmodel_graph_50_nodes.tsv │ ├── simulated_blockmodel_graph_50_nodes_truePartition.tsv │ ├── sssp_demo.cpp │ ├── triangle_count_data_ca-HepTh.tsv │ ├── triangle_count_demo.cpp │ └── vxm_timing_demo.cpp ├── graphblas │ ├── ComplementView.hpp │ ├── Matrix.hpp │ ├── StructuralComplementView.hpp │ ├── StructureView.hpp │ ├── TransposeView.hpp │ ├── Vector.hpp │ ├── algebra.hpp │ ├── detail │ │ ├── checks.hpp │ │ ├── config.hpp │ │ ├── logging.h │ │ ├── matrix_tags.hpp │ │ └── param_unpack.hpp │ ├── exceptions.hpp │ ├── graphblas.hpp │ ├── indices.hpp │ ├── matrix_utils.hpp │ ├── operations.hpp │ ├── platforms │ │ ├── README_backend.txt │ │ ├── backend_include_template.hpp │ │ ├── optimized_sequential │ │ │ ├── BitmapSparseVector.hpp │ │ │ ├── LilSparseMatrix.hpp │ │ │ ├── Matrix.hpp │ │ │ ├── Vector.hpp │ │ │ ├── backend_include.hpp │ │ │ ├── operations.hpp │ │ │ ├── optimized_sequential.hpp │ │ │ ├── sparse_apply.hpp │ │ │ ├── sparse_assign.hpp │ │ │ ├── sparse_ewiseadd.hpp │ │ │ ├── sparse_ewisemult.hpp │ │ │ ├── sparse_extract.hpp │ │ │ ├── sparse_helpers.hpp │ │ │ ├── sparse_kronecker.hpp │ │ │ ├── sparse_mxm.hpp │ │ │ ├── sparse_mxm_AB.hpp │ │ │ ├── sparse_mxm_ABT.hpp │ │ │ ├── sparse_mxm_ATB.hpp │ │ │ ├── sparse_mxm_ATBT.hpp │ │ │ ├── sparse_mxv.hpp │ │ │ ├── sparse_reduce.hpp │ │ │ ├── sparse_transpose.hpp │ │ │ └── sparse_vxm.hpp │ │ └── sequential │ │ │ ├── BitmapSparseVector.hpp │ │ │ ├── LilSparseMatrix.hpp │ │ │ ├── Matrix.hpp │ │ │ ├── Vector.hpp │ │ │ ├── backend_include.hpp │ │ │ ├── operations.hpp │ │ │ ├── sequential.hpp │ │ │ ├── sparse_apply.hpp │ │ │ ├── sparse_assign.hpp │ │ │ ├── sparse_ewiseadd.hpp │ │ │ ├── sparse_ewisemult.hpp │ │ │ ├── sparse_extract.hpp │ │ │ ├── sparse_helpers.hpp │ │ │ ├── sparse_kronecker.hpp │ │ │ ├── sparse_mxm.hpp │ │ │ ├── sparse_mxv.hpp │ │ │ ├── sparse_reduce.hpp │ │ │ ├── sparse_transpose.hpp │ │ │ ├── sparse_vxm.hpp │ │ │ └── test │ │ │ ├── run_tests.sh │ │ │ ├── test_bitmap_sparse_vector.cpp │ │ │ └── test_lil_sparse_matrix.cpp │ └── types.hpp └── test │ ├── .gitignore │ ├── test_algebra_binary.cpp │ ├── test_algebra_monoid.cpp │ ├── test_algebra_semiring.cpp │ ├── test_algebra_unary.cpp │ ├── test_apply.cpp │ ├── test_apply_binop.cpp │ ├── test_apsp.cpp │ ├── test_assign.cpp │ ├── test_bc.cpp │ ├── test_bfs.cpp │ ├── test_cluster.cpp │ ├── test_cluster_louvain.cpp │ ├── test_ewiseadd_matrix.cpp │ ├── test_ewiseadd_vector.cpp │ ├── test_ewisemult_matrix.cpp │ ├── test_ewisemult_vector.cpp │ ├── test_extract_column.cpp │ ├── test_extract_stdmat.cpp │ ├── test_extract_stdvec.cpp │ ├── test_extracttuples.cpp │ ├── test_k_truss.cpp │ ├── test_kronecker_AB.cpp │ ├── test_kronecker_ABT.cpp │ ├── test_kronecker_ATB.cpp │ ├── test_kronecker_ATBT.cpp │ ├── test_matrix_build.cpp │ ├── test_matrix_methods.cpp │ ├── test_maxflow.cpp │ ├── test_metrics.cpp │ ├── test_mis.cpp │ ├── test_mst.cpp │ ├── test_mxm.cpp │ ├── test_mxm_AB.cpp │ ├── test_mxm_ABT.cpp │ ├── test_mxm_ATB.cpp │ ├── test_mxm_ATBT.cpp │ ├── test_mxv.cpp │ ├── test_new_mxm.cpp │ ├── test_page_rank.cpp │ ├── test_reduce.cpp │ ├── test_sssp.cpp │ ├── test_transpose.cpp │ ├── test_triangle_count.cpp │ ├── test_vector_methods.cpp │ ├── test_version.cpp │ ├── test_views.cpp │ └── test_vxm.cpp └── timing_data.tsv /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | #*# 3 | .#* 4 | ~$* 5 | *.bak 6 | *.map 7 | .DS_Store 8 | .tox 9 | *.map 10 | autom4te.cache 11 | build 12 | docs 13 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Version 3.0 Contributors 2 | ------------------------ 3 | 4 | Scott McMillan Software Engineering Institute/Carnegie Mellon University 5 | Marcin Zalewski Pacific Northwest National Laboratory/Battelle Memorial Institute 6 | 7 | ============================================================================== 8 | 9 | Version 2.0 Contributors 10 | ------------------------ 11 | 12 | Scott McMillan Software Engineering Institute/Carnegie Mellon University 13 | Andrew Mellinger SEI/CMU 14 | Oren Wright SEI/CMU 15 | Jason Larkin SEI/CMU 16 | Andrew Lumsdaine Pacific Northwest National Laboratory/Battelle Memorial Institute 17 | Marcin Zalewski PNNL/Battelle 18 | 19 | ============================================================================== 20 | 21 | Version 1.0 Contributors 22 | ------------------------ 23 | 24 | Scott McMillan Software Engineering Institute/Carnegie Mellon University 25 | Jonathan Chu SEI/CMU 26 | Samantha Misurda SEI/CMU 27 | John Matty SEI/CMU 28 | Andrew Mellinger SEI/CMU 29 | Andrew Lumsdaine Center for Research in ExaScale Technologies/Indiana University 30 | Marcin Zalewski CREST/IU 31 | Eric Holk CREST/IU 32 | Peter Zhang/Aaltonen CREST/IU 33 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | See LICENSE file. 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GraphBLAS Template Library (GBTL), Version 3.0 2 | 3 | Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 4 | Authors. All Rights Reserved. 5 | 6 | BSD (SEI) 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | 3. Products derived from this software may not include “Carnegie Mellon 19 | University,” "SEI” and/or “Software Engineering Institute" in the name of 20 | such derived product, nor shall “Carnegie Mellon University,” "SEI” and/or 21 | “Software Engineering Institute" be used to endorse or promote products 22 | derived from this software without prior written permission. For written 23 | permission, please contact permission@sei.cmu.edu. 24 | 25 | ACKNOWLEDGMENTS AND DISCLAIMERS: 26 | 27 | GraphBLAS Template Library (GBTL), Version 3.0 includes and/or can make use 28 | of certain third party software ("Third Party Software"). The Third Party 29 | Software that is used by GraphBLAS Template Library (GBTL), Version 3.0 is 30 | dependent upon your system configuration, but typically includes the software 31 | identified below. By using GraphBLAS Template Library (GBTL), Version 3.0, 32 | You agree to comply with any and all relevant Third Party Software terms and 33 | conditions contained in any such Third Party Software or separate license 34 | file distributed with such Third Party Software. The parties who own the 35 | Third Party Software ("Third Party Licensors") are intended third party 36 | beneficiaries to this License with respect to the terms applicable to their 37 | Third Party Software. Third Party Software licenses only apply to the Third 38 | Party Software and not any other portion of GraphBLAS Template Library 39 | (GBTL), Version 3.0 or GraphBLAS Template Library (GBTL), Version 3.0 as a 40 | whole. 41 | 42 | ACKNOWLEDGMENTS AND DISCLAIMERS: 43 | 44 | This material is based upon work funded and supported by the United States 45 | Department of Defense under Contract No. FA8702-15-D-0002 with Carnegie 46 | Mellon University for the operation of the Software Engineering Institute, a 47 | federally funded research and development center and by the United States 48 | Department of Energy under Contract DE-AC05-76RL01830 with Battelle Memorial 49 | Institute for the Operation of the Pacific Northwest National Laboratory. 50 | 51 | THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 52 | THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 53 | UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 54 | DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 55 | EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 56 | DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 57 | ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 58 | OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 59 | DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 60 | RIGHTS. 61 | 62 | Reference herein to any specific commercial product, process, or service by 63 | trade name, trademark, manufacturer, or otherwise does not necessarily 64 | constitute or imply its endorsement, recommendation, or favoring by the 65 | United States Government or any agency thereof, or Carnegie Mellon 66 | University, or Battelle Memorial Institute. The views and opinions of authors 67 | expressed herein do not necessarily state or reflect those of the United 68 | States Government or any agency thereof. 69 | 70 | Please see “AUTHORS” file for a list of known contributors. 71 | 72 | [DISTRIBUTION STATEMENT A] This material has been approved for public release 73 | and unlimited distribution. Please see Copyright notice for non-US 74 | Government use and distribution. 75 | 76 | This Software includes and/or makes use of the following Third-Party Software 77 | subject to its own license: 78 | 79 | 1. Boost Unit Test Framework 80 | (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 81 | Copyright 2001 Boost software license, Gennadiy Rozental. 82 | Boost Software License - Version 1.0 - August 17th, 2003 83 | 84 | Permission is hereby granted, free of charge, to any person or organization 85 | obtaining a copy of the software and accompanying documentation covered by 86 | this license (the "Software") to use, reproduce, display, distribute, 87 | execute, and transmit the Software, and to prepare derivative works of the 88 | Software, and to permit third-parties to whom the Software is furnished to do 89 | so, all subject to the following: 90 | 91 | The copyright notices in the Software and this entire statement, including 92 | the above license grant, this restriction and the following disclaimer, must 93 | be included in all copies of the Software, in whole or in part, and all 94 | derivative works of the Software, unless such copies or derivative works are 95 | solely in the form of machine-executable object code generated by a source 96 | language processor. 97 | 98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 99 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 100 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 101 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR 102 | ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 103 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 104 | DEALINGS IN THE SOFTWARE. 105 | 106 | This release is an update of: 107 | 108 | 1. GraphBLAS Template Library (GBTL) 109 | (https://github.com/cmu-sei/gbtl/blob/1.0.0/LICENSE) Copyright 2015 Carnegie 110 | Mellon University and The Trustees of Indiana. DM17-0037, DM-0002659 111 | 112 | 2. GraphBLAS Template Library (GBTL) 113 | (https://github.com/cmu-sei/gbtl/blob/2.0.0/LICENSE) Copyright 2018 Carnegie 114 | Mellon University, Battelle Memorial Institute, and Authors. DM18-0559 115 | 116 | DM20-0442 117 | -------------------------------------------------------------------------------- /clean_cmake.sh: -------------------------------------------------------------------------------- 1 | rm -rf CMakeFiles 2 | rm Makefile 3 | rm CMakeCache.txt 4 | rm cmake_install.cmake 5 | -------------------------------------------------------------------------------- /new_build.txt: -------------------------------------------------------------------------------- 1 | This project is designed to use cmake to build and use an "out of source" style build to make it easy to clean up. We build in to a "build" directory by following these steps: 2 | 3 | mkdir build 4 | cd build 5 | cmake ../src 6 | make 7 | 8 | I ususally do: "make -i -j 8" to ignore errors (try to build every test) and to use all my cores. 9 | 10 | There is a convenience script to do this from scratch called rebuild.sh that also removes all the old content from a previous use of clean_build.sh. 11 | 12 | For CLion support in the cmake project settings "Build, Execution, Deployment > CMake > Generation path:" I set it to ../build. This sets it to use the same make files as that created by the clean build process so that there aren't two different build trees. 13 | 14 | There is also a script called "clean_cmake.sh" that removes all the files, if cmake is run in the src directory or in the root (gbtl) directory. 15 | 16 | 17 | -------------------------------------------------------------------------------- /rebuild.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | rm -rf build 4 | mkdir build 5 | cd build 6 | cmake ../src 7 | make -i -j 8 8 | 9 | -------------------------------------------------------------------------------- /run_tests.sh: -------------------------------------------------------------------------------- 1 | # Call this script with an optional build directory name (defaults to ./build) 2 | echo Running all tests found in ${1-build}/bin... 3 | find ${1-build}/bin -name "test_*" -perm /u+x | while read test; do echo "Now running $test..." && ./$test && echo ""; done 4 | -------------------------------------------------------------------------------- /run_tests2.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Call this script with an optional build directory name (defaults to ./build) 4 | 5 | export FAILED=0 6 | echo "Running all tests found in ${1-build}/bin and placing output into: test.out" 7 | rm test.out 8 | 9 | # Note the good parenthesis before the read and after the end so that failed is in one subshell 10 | find ${1-build}/bin -name "test_*" -perm /u+x | ( while read test; do 11 | #echo "Now running $test..." && ./$test && echo ""; 12 | echo "Now running $test..." >> test.out 13 | ./$test >> test.out 2>&1 14 | 15 | if [ $? != 0 ]; then 16 | echo "Failure in test: $test" 17 | let "FAILED++" 18 | fi 19 | done 20 | echo "Failed ${FAILED} test."; exit ${FAILED} ) 21 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # GraphBLAS Template Library (GBTL), Version 3.0 2 | # 3 | # Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 4 | # Authors. 5 | # 6 | # THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 7 | # THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 8 | # UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 9 | # DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 10 | # EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 11 | # DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 12 | # ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 13 | # OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 14 | # DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 15 | # RIGHTS. 16 | # 17 | # Released under a BSD-style license, please see LICENSE file or contact 18 | # permission@sei.cmu.edu for full terms. 19 | # 20 | # [DISTRIBUTION STATEMENT A] This material has been approved for public release 21 | # and unlimited distribution. Please see Copyright notice for non-US 22 | # Government use and distribution. 23 | # 24 | # DM20-0442 25 | 26 | cmake_minimum_required(VERSION 2.8) 27 | 28 | project(GRAPHBLAS_TEMPLATE_LIBRARY_3) 29 | 30 | # For debugging 31 | message("CMake SRC: ${CMAKE_SOURCE_DIR}") 32 | message("Project Name: ${PROJECT_NAME}") 33 | message("Bin Directory: ${CMAKE_BINARY_DIR}") 34 | message("Project Name: ${CMAKE_SOURCE_DIR}") 35 | message("Project Bin Directory: ${PROJECT_BINARY_DIR}") 36 | 37 | # Default platform is sequential 38 | if (NOT PLATFORM) 39 | set(PLATFORM sequential) 40 | endif() 41 | 42 | message("Configuring platform: ${PLATFORM}") 43 | 44 | if (EXISTS ${CMAKE_SOURCE_DIR}/graphblas/platforms/${PLATFORM}) 45 | set(PLATFORM_SOURCE_DIR ${CMAKE_SOURCE_DIR}/graphblas/platforms/${PLATFORM}) 46 | else() 47 | unset(PLATFORM CACHE) 48 | message(FATAL_ERROR "Specified platform directory does not exist.") 49 | endif() 50 | 51 | message("Configured platform: ${PLATFORM}") 52 | 53 | # https://stackoverflow.com/questions/14306642/adding-multiple-executables-in-cmake 54 | 55 | # This seems hokey that we need to include the root as our directory 56 | include_directories(${CMAKE_SOURCE_DIR} ${PLATFORM_SOURCE_DIR}) 57 | 58 | # Compiler flags 59 | set(CMAKE_CXX_STANDARD 17) 60 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") 61 | 62 | # Build a list of all the graphblas headers. 63 | file(GLOB GRAPHBLAS_HEADERS graphblas/*.hpp) 64 | 65 | # Build tests and demos into a separate bin directory so it doesn't get mixed in 66 | # with settings and config files. Note the library dependency is not in here. 67 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 68 | 69 | ### Make basic tests 70 | file( GLOB TEST_SOURCES LIST_DIRECTORIES false ${CMAKE_SOURCE_DIR}/test/*.cpp ) 71 | foreach( testsourcefile ${TEST_SOURCES} ) 72 | get_filename_component(justname ${testsourcefile} NAME) 73 | string( REPLACE ".cpp" "" testname ${justname} ) 74 | message("Adding: ${testname}") 75 | add_executable( ${testname} ${testsourcefile} ${GRAPHBLAS_HEADERS}) 76 | endforeach( testsourcefile ${TEST_SOURCES} ) 77 | 78 | ### Make extra PLATFORM-specific tests 79 | file( GLOB TEST_SOURCES LIST_DIRECTORIES false ${PLATFORM_SOURCE_DIR}/test/*.cpp ) 80 | foreach( testsourcefile ${TEST_SOURCES} ) 81 | get_filename_component(justname ${testsourcefile} NAME) 82 | string( REPLACE ".cpp" "" testname ${justname} ) 83 | message("Adding: ${testname}_${PLATFORM} ") 84 | add_executable( ${testname}_${PLATFORM} ${testsourcefile} ${GRAPHBLAS_HEADERS}) 85 | endforeach( testsourcefile ${TEST_SOURCES} ) 86 | 87 | ## Make demos 88 | file( GLOB TEST_SOURCES LIST_DIRECTORIES false ${CMAKE_SOURCE_DIR}/demo/*.cpp ) 89 | foreach( testsourcefile ${TEST_SOURCES} ) 90 | get_filename_component(justname ${testsourcefile} NAME) 91 | string( REPLACE ".cpp" "" testname ${justname} ) 92 | message("Adding: ${testname}") 93 | add_executable( ${testname} ${testsourcefile} ${GRAPHBLAS_HEADERS}) 94 | endforeach( testsourcefile ${TEST_SOURCES} ) 95 | -------------------------------------------------------------------------------- /src/algorithms/algorithms.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | -------------------------------------------------------------------------------- /src/algorithms/apsp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace algorithms 37 | { 38 | /** 39 | * @brief Given a graph, G = (V,E), with edge weights w and no negative 40 | * weight cycles, this algorithm returns the shortest path 41 | * distances for all vertex pairs (in a dense NxN matrix). 42 | * This implements Floyd-Warshall. 43 | * 44 | * @param[in] graph The adjacency matrix of the graph for which APSP 45 | * will be computed. Entries are edge weights. 46 | * @return A dense matrix where entry u,v contains 47 | * the distance (edge weight sum) of shortest path 48 | * from vertex u to vertex v. 49 | */ 50 | template 51 | grb::Matrix apsp(MatrixT const &graph) 52 | { 53 | using T = typename MatrixT::ScalarType; 54 | 55 | grb::IndexType num_vertices(graph.nrows()); 56 | if (num_vertices != graph.ncols()) 57 | { 58 | throw grb::DimensionException(); 59 | } 60 | 61 | auto Distances(grb::scaled_identity>(num_vertices, 0)); 62 | grb::eWiseAdd(Distances, 63 | grb::NoMask(), grb::NoAccumulate(), 64 | grb::Plus(), 65 | Distances, 66 | graph); 67 | grb::Matrix col_k(num_vertices, 1); 68 | grb::IndexArrayType row_indices(1); 69 | grb::Matrix row_k(1, num_vertices); 70 | 71 | for (grb::IndexType k = 0; k < num_vertices; ++k) 72 | { 73 | row_indices[0] = k; 74 | grb::extract(row_k, 75 | grb::NoMask(), 76 | grb::NoAccumulate(), 77 | Distances, 78 | row_indices, grb::AllIndices()); 79 | 80 | grb::extract(col_k, 81 | grb::NoMask(), 82 | grb::NoAccumulate(), 83 | Distances, 84 | grb::AllIndices(), row_indices); 85 | 86 | grb::mxm(Distances, 87 | grb::NoMask(), 88 | grb::Min(), 89 | grb::MinPlusSemiring(), 90 | col_k, row_k); 91 | 92 | //std::cout << "============== Distances for Iteration " << k 93 | // << std::endl; 94 | //grb::print_matrix(std::cout, Distances, "Distances"); 95 | } 96 | return Distances; 97 | } 98 | } // algorithms 99 | -------------------------------------------------------------------------------- /src/demo/.gitignore: -------------------------------------------------------------------------------- 1 | CscMatrixDemo 2 | CsrMatrixDemo 3 | LilMatrix_demo 4 | apply_demo 5 | assign_demo 6 | bfs_demo 7 | demo 8 | dia_demo 9 | ewiseapply_demo 10 | extract_demo 11 | extracttuples_demo 12 | gemm_demo 13 | sssp_demo 14 | peer_pressure_demo -------------------------------------------------------------------------------- /src/demo/Timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | //**************************************************************************** 33 | template 35 | class Timer 36 | { 37 | public: 38 | using TimeType = std::chrono::time_point; 39 | 40 | Timer() : start_time(), stop_time() {} 41 | 42 | TimeType start() { return (start_time = ClockT::now()); } 43 | TimeType stop() { return (stop_time = ClockT::now()); } 44 | 45 | double elapsed() const 46 | { 47 | return std::chrono::duration_cast( 48 | stop_time - start_time).count(); 49 | } 50 | 51 | private: 52 | TimeType start_time, stop_time; 53 | }; 54 | -------------------------------------------------------------------------------- /src/demo/bfs_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | int main() 35 | { 36 | // FA Tech Note graph 37 | // 38 | // {-, -, -, 1, -, -, -, -, -}, 39 | // {-, -, -, 1, -, -, 1, -, -}, 40 | // {-, -, -, -, 1, 1, 1, -, 1}, 41 | // {1, 1, -, -, 1, -, 1, -, -}, 42 | // {-, -, 1, 1, -, -, -, -, 1}, 43 | // {-, -, 1, -, -, -, -, -, -}, 44 | // {-, 1, 1, 1, -, -, -, -, -}, 45 | // {-, -, -, -, -, -, -, -, -}, 46 | // {-, -, 1, -, 1, -, -, -, -}; 47 | 48 | /// @todo change scalar type to unsigned int or grb::IndexType 49 | using T = grb::IndexType; 50 | using GBMatrix = grb::Matrix; 51 | //T const INF(std::numeric_limits::max()); 52 | 53 | grb::IndexType const NUM_NODES = 9; 54 | grb::IndexArrayType i = {0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 55 | 4, 4, 4, 5, 6, 6, 6, 8, 8}; 56 | grb::IndexArrayType j = {3, 3, 6, 4, 5, 6, 8, 0, 1, 4, 6, 57 | 2, 3, 8, 2, 1, 2, 3, 2, 4}; 58 | std::vector v(i.size(), 1); 59 | 60 | GBMatrix G_tn(NUM_NODES, NUM_NODES); 61 | G_tn.build(i.begin(), j.begin(), v.begin(), i.size()); 62 | grb::print_matrix(std::cout, G_tn, "Graph adjacency matrix:"); 63 | 64 | // Perform a single BFS 65 | grb::Vector parent_list(NUM_NODES); 66 | grb::Vector root(NUM_NODES); 67 | root.setElement(3, 1); 68 | algorithms::bfs(G_tn, root, parent_list); 69 | grb::print_vector(std::cout, parent_list, "Parent list for root at vertex 3"); 70 | 71 | // Perform BFS from all roots simultaneously (should the value be 0?) 72 | //auto roots = grb::identity(NUM_NODES, INF, 0); 73 | GBMatrix roots(NUM_NODES, NUM_NODES); 74 | grb::IndexArrayType ii, jj, vv; 75 | for (grb::IndexType ix = 0; ix < NUM_NODES; ++ix) 76 | { 77 | ii.push_back(ix); 78 | jj.push_back(ix); 79 | vv.push_back(1); 80 | } 81 | roots.build(ii, jj, vv); 82 | 83 | GBMatrix G_tn_res(NUM_NODES, NUM_NODES); 84 | 85 | algorithms::bfs_batch(G_tn, roots, G_tn_res); 86 | 87 | grb::print_matrix(std::cout, G_tn_res, "Parents for each root (by rows):"); 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /src/demo/bfs_level_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | grb::IndexType const num_nodes = 34; 34 | grb::IndexArrayType i = { 35 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 36 | 1,1,1,1,1,1,1,1,1, 37 | 2,2,2,2,2,2,2,2,2,2, 38 | 3,3,3,3,3,3, 39 | 4,4,4, 40 | 5,5,5,5, 41 | 6,6,6,6, 42 | 7,7,7,7, 43 | 8,8,8,8,8, 44 | 9,9, 45 | 10,10,10, 46 | 11, 47 | 12,12, 48 | 13,13,13,13,13, 49 | 14,14, 50 | 15,15, 51 | 16,16, 52 | 17,17, 53 | 18,18, 54 | 19,19,19, 55 | 20,20, 56 | 21,21, 57 | 22,22, 58 | 23,23,23,23,23, 59 | 24,24,24, 60 | 25,25,25, 61 | 26,26, 62 | 27,27,27,27, 63 | 28,28,28, 64 | 29,29,29,29, 65 | 30,30,30,30, 66 | 31,31,31,31,31,31, 67 | 32,32,32,32,32,32,32,32,32,32,32,32, 68 | 33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33}; 69 | 70 | grb::IndexArrayType j = { 71 | 1,2,3,4,5,6,7,8,10,11,12,13,19,21,23,31, 72 | 0,2,3,7,13,17,19,21,30, 73 | 0,1,3,7,8,9,13,27,28,32, 74 | 0,1,2,7,12,13, 75 | 0,6,10, 76 | 0,6,10,16, 77 | 0,4,5,16, 78 | 0,1,2,3, 79 | 0,2,30,32,33, 80 | 2,33, 81 | 0,4,5, 82 | 0, 83 | 0,3, 84 | 0,1,2,3,33, 85 | 32,33, 86 | 32,33, 87 | 5,6, 88 | 0,1, 89 | 32,33, 90 | 0,1,33, 91 | 32,33, 92 | 0,1, 93 | 32,33, 94 | 25,27,29,32,33, 95 | 25,27,31, 96 | 23,24,31, 97 | 29,33, 98 | 2,23,24,33, 99 | 2,31,33, 100 | 23,26,32,33, 101 | 1,8,32,33, 102 | 0,24,25,28,32,33, 103 | 2,8,14,15,18,20,22,23,29,30,31,33, 104 | 8,9,13,14,15,18,19,20,22,23,26,27,28,29,30,31,32}; 105 | 106 | 107 | //**************************************************************************** 108 | int main() 109 | { 110 | // TODO Assignment from Initalizer list. 111 | grb::Matrix G_karate(num_nodes, num_nodes); 112 | std::vector weights(i.size(), 1); 113 | 114 | G_karate.build(i.begin(), j.begin(), weights.begin(), i.size()); 115 | 116 | // Trying the row vector approach 117 | grb::Matrix root(1, num_nodes); 118 | // pick an arbitrary root: 119 | root.setElement(0, 30, 1); 120 | 121 | grb::Matrix levels1(1, num_nodes); 122 | grb::Matrix levels(1, num_nodes); 123 | 124 | algorithms::bfs_level(G_karate, root, levels1); 125 | 126 | // std::cout << "Graph: " << std::endl; 127 | // grb::print_matrix(std::cout, G_karate); 128 | std::cout << "bfs_level output" << std::endl; 129 | std::cout << "root:" << std::endl; 130 | grb::print_matrix(std::cout, root); 131 | std::cout << "levels:" << std::endl; 132 | grb::print_matrix(std::cout, levels1); 133 | 134 | algorithms::batch_bfs_level_masked(G_karate, root, levels); 135 | 136 | // std::cout << "Graph: " << std::endl; 137 | // grb::print_matrix(std::cout, G_karate); 138 | std::cout << std::endl; 139 | std::cout << "root:" << std::endl; 140 | grb::print_matrix(std::cout, root); 141 | std::cout << "levels:" << std::endl; 142 | grb::print_matrix(std::cout, levels); 143 | 144 | return 0; 145 | } 146 | -------------------------------------------------------------------------------- /src/demo/k_truss_data.tsv: -------------------------------------------------------------------------------- 1 | 0 1 2 | 1 2 3 | 0 3 4 | 2 3 5 | 0 2 6 | 1 4 7 | -------------------------------------------------------------------------------- /src/demo/k_truss_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | using namespace grb; 36 | 37 | //**************************************************************************** 38 | namespace 39 | { 40 | IndexArrayType i = { 41 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 42 | 1,1,1,1,1,1,1,1,1, 43 | 2,2,2,2,2,2,2,2,2,2, 44 | 3,3,3,3,3,3, 45 | 4,4,4, 46 | 5,5,5,5, 47 | 6,6,6,6, 48 | 7,7,7,7, 49 | 8,8,8,8,8, 50 | 9,9, 51 | 10,10,10, 52 | 11, 53 | 12,12, 54 | 13,13,13,13,13, 55 | 14,14, 56 | 15,15, 57 | 16,16, 58 | 17,17, 59 | 18,18, 60 | 19,19,19, 61 | 20,20, 62 | 21,21, 63 | 22,22, 64 | 23,23,23,23,23, 65 | 24,24,24, 66 | 25,25,25, 67 | 26,26, 68 | 27,27,27,27, 69 | 28,28,28, 70 | 29,29,29,29, 71 | 30,30,30,30, 72 | 31,31,31,31,31, 73 | 32,32,32,32,32,32,32,32,32,32,32,32, 74 | 33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33}; 75 | 76 | IndexArrayType j = { 77 | 1,2,3,4,5,6,7,8,10,11,12,13,17,19,21,31, //1,2,3,4,5,6,7,8,10,11,12,13,19,21,23,31, 78 | 0,2,3,7,13,17,19,21,30, 79 | 0,1,3,7,8,9,13,27,28,32, 80 | 0,1,2,7,12,13, 81 | 0,6,10, 82 | 0,6,10,16, 83 | 0,4,5,16, 84 | 0,1,2,3, 85 | 0,2,30,32,33, 86 | 2,33, 87 | 0,4,5, 88 | 0, 89 | 0,3, 90 | 0,1,2,3,33, 91 | 32,33, 92 | 32,33, 93 | 5,6, 94 | 0,1, 95 | 32,33, 96 | 0,1,33, 97 | 32,33, 98 | 0,1, 99 | 32,33, 100 | 25,27,29,32,33, 101 | 25,27,31, 102 | 23,24,31, 103 | 29,33, 104 | 2,23,24,33, 105 | 2,31,33, 106 | 23,26,32,33, 107 | 1,8,32,33, 108 | 0,24,25,32,33, //0,24,25,28,32,33, 109 | 2,8,14,15,18,20,22,23,29,30,31,33, 110 | 8,9,13,14,15,18,19,20,22,23,26,27,28,29,30,31,32}; 111 | 112 | } 113 | 114 | //**************************************************************************** 115 | int main(int argc, char **argv) 116 | { 117 | using T = int; 118 | 119 | // create an incidence matrix from the data 120 | IndexType num_edges = 0; 121 | IndexType num_nodes = 0; 122 | IndexArrayType edge_array, node_array; 123 | // count edges in upper triangle of A 124 | for (IndexType ix = 0; ix < i.size(); ++ix) 125 | { 126 | if (i[ix] < j[ix]) 127 | { 128 | edge_array.push_back(num_edges); 129 | node_array.push_back(i[ix]); 130 | edge_array.push_back(num_edges); 131 | node_array.push_back(j[ix]); 132 | ++num_edges; 133 | 134 | num_nodes = std::max(num_nodes, i[ix]); 135 | num_nodes = std::max(num_nodes, j[ix]); 136 | } 137 | } 138 | ++num_nodes; 139 | std::vector v(edge_array.size(), 1); 140 | 141 | Matrix E(num_edges, num_nodes); 142 | E.build(edge_array.begin(), node_array.begin(), v.begin(), v.size()); 143 | print_matrix(std::cout, E, "Incidence"); 144 | 145 | std::cout << "Running k-truss algorithm..." << std::endl; 146 | 147 | auto Eout3 = algorithms::k_truss(E, 3); 148 | std::cout << "===============================================" << std::endl; 149 | print_matrix(std::cout, Eout3, "Edges in 3-trusses"); 150 | std::cout << "===============================================" << std::endl; 151 | 152 | auto Eout4 = algorithms::k_truss(Eout3, 4); 153 | std::cout << "===============================================" << std::endl; 154 | print_matrix(std::cout, Eout4, "Edges in 4-trusses"); 155 | std::cout << "===============================================" << std::endl; 156 | 157 | auto Eout5 = algorithms::k_truss(Eout4, 5); 158 | std::cout << "===============================================" << std::endl; 159 | print_matrix(std::cout, Eout5, "Edges in 5-trusses"); 160 | std::cout << "===============================================" << std::endl; 161 | 162 | auto Eout6 = algorithms::k_truss(Eout5, 6); 163 | std::cout << "===============================================" << std::endl; 164 | print_matrix(std::cout, Eout6, "Edges in 6-trusses"); 165 | std::cout << "===============================================" << std::endl; 166 | return 0; 167 | } 168 | -------------------------------------------------------------------------------- /src/demo/louvain_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define GRAPHBLAS_DEBUG 1 33 | 34 | #include 35 | #include 36 | #include "Timer.hpp" 37 | 38 | //**************************************************************************** 39 | int main(int argc, char **argv) 40 | { 41 | if (argc < 2) 42 | { 43 | std::cerr << "ERROR: too few arguments." << std::endl; 44 | exit(1); 45 | } 46 | 47 | // Read the edgelist and create the tuple arrays 48 | std::string pathname(argv[1]); 49 | std::ifstream infile(pathname); 50 | grb::IndexArrayType iA; 51 | grb::IndexArrayType jA; 52 | std::vector weights; 53 | uint64_t num_rows = 0; 54 | uint64_t max_id = 0; 55 | uint64_t src, dst, weight; 56 | while (infile) 57 | { 58 | infile >> src >> dst >> weight; 59 | src -= 1; 60 | dst -= 1; 61 | //std::cout << "Read: " << src << ", " << dst << std::endl; 62 | if (src > max_id) max_id = src; 63 | if (dst > max_id) max_id = dst; 64 | 65 | // if (src != dst) // ignore self loops 66 | iA.push_back(src); 67 | jA.push_back(dst); 68 | weights.push_back((double)weight); 69 | 70 | ++num_rows; 71 | } 72 | std::cout << "Read " << num_rows << " rows." << std::endl; 73 | std::cout << "#Nodes = " << (max_id + 1) << std::endl; 74 | 75 | grb::IndexType NUM_NODES(max_id + 1); 76 | 77 | using MatType = grb::Matrix; 78 | 79 | MatType A(NUM_NODES, NUM_NODES); 80 | A.build(iA.begin(), jA.begin(), weights.begin(), iA.size()); 81 | 82 | std::cout << "Running louvain clustering..." << std::endl; 83 | 84 | Timer my_timer; 85 | 86 | // Perform clustering with 2 different algorithms 87 | //=================== 88 | my_timer.start(); 89 | auto cluster_matrix = algorithms::louvain_cluster(A); 90 | my_timer.stop(); 91 | 92 | std::cout << "Elapsed time: " << my_timer.elapsed() << " msec." << std::endl; 93 | auto cluster_assignments = 94 | algorithms::get_louvain_cluster_assignments(cluster_matrix); 95 | print_vector(std::cout, cluster_assignments, "cluster assignments"); 96 | 97 | //=================== 98 | my_timer.start(); 99 | auto cluster2_matrix = algorithms::louvain_cluster_masked(A); 100 | my_timer.stop(); 101 | 102 | std::cout << "Elapsed time: " << my_timer.elapsed() << " msec." << std::endl; 103 | auto cluster2_assignments = 104 | algorithms::get_louvain_cluster_assignments(cluster2_matrix); 105 | print_vector(std::cout, cluster2_assignments, "cluster (masked) assignments"); 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /src/demo/louvain_karate_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define GRAPHBLAS_DEBUG 1 33 | 34 | #include 35 | #include 36 | #include "Timer.hpp" 37 | 38 | //**************************************************************************** 39 | grb::IndexType const NUM_NODES = 34; 40 | 41 | grb::IndexArrayType i = { 42 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 43 | 1,1,1,1,1,1,1,1,1, 44 | 2,2,2,2,2,2,2,2,2,2, 45 | 3,3,3,3,3,3, 46 | 4,4,4, 47 | 5,5,5,5, 48 | 6,6,6,6, 49 | 7,7,7,7, 50 | 8,8,8,8,8, 51 | 9,9, 52 | 10,10,10, 53 | 11, 54 | 12,12, 55 | 13,13,13,13,13, 56 | 14,14, 57 | 15,15, 58 | 16,16, 59 | 17,17, 60 | 18,18, 61 | 19,19,19, 62 | 20,20, 63 | 21,21, 64 | 22,22, 65 | 23,23,23,23,23, 66 | 24,24,24, 67 | 25,25,25, 68 | 26,26, 69 | 27,27,27,27, 70 | 28,28,28, 71 | 29,29,29,29, 72 | 30,30,30,30, 73 | 31,31,31,31,31, 74 | 32,32,32,32,32,32,32,32,32,32,32,32, 75 | 33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33}; 76 | 77 | grb::IndexArrayType j = { 78 | 1,2,3,4,5,6,7,8,10,11,12,13,17,19,21,31, //1,2,3,4,5,6,7,8,10,11,12,13,19,21,23,31, 79 | 0,2,3,7,13,17,19,21,30, 80 | 0,1,3,7,8,9,13,27,28,32, 81 | 0,1,2,7,12,13, 82 | 0,6,10, 83 | 0,6,10,16, 84 | 0,4,5,16, 85 | 0,1,2,3, 86 | 0,2,30,32,33, 87 | 2,33, 88 | 0,4,5, 89 | 0, 90 | 0,3, 91 | 0,1,2,3,33, 92 | 32,33, 93 | 32,33, 94 | 5,6, 95 | 0,1, 96 | 32,33, 97 | 0,1,33, 98 | 32,33, 99 | 0,1, 100 | 32,33, 101 | 25,27,29,32,33, 102 | 25,27,31, 103 | 23,24,31, 104 | 29,33, 105 | 2,23,24,33, 106 | 2,31,33, 107 | 23,26,32,33, 108 | 1,8,32,33, 109 | 0,24,25,32,33, //0,24,25,28,32,33, 110 | 2,8,14,15,18,20,22,23,29,30,31,33, 111 | 8,9,13,14,15,18,19,20,22,23,26,27,28,29,30,31,32}; 112 | 113 | //**************************************************************************** 114 | int main(int argc, char **argv) 115 | { 116 | using MatType = grb::Matrix; 117 | MatType A(NUM_NODES, NUM_NODES); 118 | 119 | // Read the edgelist and create the tuple arrays 120 | if (i.size() != j.size()) 121 | { 122 | std::cerr << "Index arrays are not the same size: " << i.size() 123 | << " != " << j.size() << std::endl; 124 | return -1; 125 | } 126 | 127 | std::vector weights(i.size(), 1.0); 128 | A.build(i.begin(), j.begin(), weights.begin(), i.size()); 129 | 130 | std::cout << "Running louvain clustering..." << std::endl; 131 | 132 | Timer my_timer; 133 | 134 | // Perform louvain clustering with different random seeds 135 | //=================== 136 | for (int seed = 0; seed < 20; ++seed) 137 | { 138 | my_timer.start(); 139 | auto cluster_matrix = algorithms::louvain_cluster(A, (double)seed); 140 | my_timer.stop(); 141 | 142 | std::cout << "Elapsed time: " << my_timer.elapsed() << " msec." 143 | << std::endl; 144 | auto cluster_assignments = 145 | algorithms::get_louvain_cluster_assignments(cluster_matrix); 146 | print_vector(std::cout, cluster_assignments, "cluster assignments"); 147 | } 148 | 149 | // Perform louvain2 clustering with different random seeds 150 | //=================== 151 | for (int seed = 0; seed < 20; ++seed) 152 | { 153 | my_timer.start(); 154 | auto cluster_matrix = algorithms::louvain_cluster_masked(A, (double)seed); 155 | my_timer.stop(); 156 | 157 | std::cout << "Elapsed time: " << my_timer.elapsed() << " msec." 158 | << std::endl; 159 | auto cluster_assignments = 160 | algorithms::get_louvain_cluster_assignments(cluster_matrix); 161 | print_vector(std::cout, cluster_assignments, "cluster (masked) assignments"); 162 | } 163 | 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /src/demo/masked_mxm_homework.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | using namespace grb; 36 | 37 | //**************************************************************************** 38 | namespace 39 | { 40 | //************************************************************************ 41 | /** 42 | * @brief Perform a breadth first search (BFS) on the given graph. 43 | * 44 | * @param[in] graph NxN adjacency matrix of the graph on which to 45 | * perform a BFS (not the transpose). A value of 46 | * 1 indicates an edge (structural zero = 0). 47 | * @param[in] wavefront RxN initial wavefronts to use in the calculation 48 | * of R simultaneous traversals. A value of 1 in a 49 | * given row indicates a root for the corresponding 50 | * traversal. (structural zero = 0). 51 | * @param[out] levels The level (distance in unweighted graphs) from 52 | * the corresponding root of that BFS. Roots are 53 | * assigned a value of 1. (a value of 0 implies not 54 | * reachable. 55 | */ 56 | template 58 | void bfs_level_masked(MatrixT const &graph, 59 | WavefrontMatrixT wavefront, //row vector, copy made 60 | Matrix &levels) 61 | { 62 | /// Assert graph is square/have a compatible shape with wavefront 63 | IndexType grows(graph.nrows()); 64 | IndexType gcols(graph.ncols()); 65 | IndexType cols(wavefront.ncols()); 66 | 67 | if ((grows != gcols) || (cols != grows)) 68 | { 69 | throw DimensionException("grows="+std::to_string(grows) 70 | + ", gcols"+std::to_string(gcols) 71 | + "\ncols="+std::to_string(cols) 72 | + ", grows="+std::to_string(grows)); 73 | } 74 | 75 | IndexType depth = 0; 76 | while (wavefront.nvals() > 0) 77 | { 78 | // Increment the level 79 | ++depth; 80 | 81 | // Apply the level to all newly visited nodes 82 | apply(levels, NoMask(), Plus(), 83 | std::bind(Times(), 84 | std::placeholders::_1, 85 | depth), 86 | wavefront); 87 | 88 | // Advance the wavefront and mask out nodes already assigned levels 89 | mxm(wavefront, 90 | complement(levels), NoAccumulate(), 91 | LogicalSemiring(), 92 | wavefront, graph, REPLACE); 93 | } 94 | } 95 | } 96 | 97 | 98 | //**************************************************************************** 99 | int main(int, char**) 100 | { 101 | // syntatic sugar 102 | using ScalarType = IndexType; 103 | 104 | // Create an adjacency matrix for "Gilbert's" directed graph 105 | IndexType const NUM_NODES(7); 106 | IndexArrayType i = {0, 0, 1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6}; 107 | IndexArrayType j = {1, 3, 4, 6, 5, 0, 2, 6, 5, 2, 2, 3, 4}; 108 | std::vector v(i.size(), 1.0); 109 | 110 | Matrix graph(NUM_NODES, NUM_NODES); 111 | graph.build(i.begin(), j.begin(), v.begin(), i.size()); 112 | 113 | print_matrix(std::cout, graph, "Test Graph:"); 114 | // Outputs: 115 | // Test Graph:: structural zero = 0 116 | // [[ , 1, , 1, , , ] 117 | // [ , , , , 1, , 1] 118 | // [ , , , , , 1, ] 119 | // [1, , 1, , , , 1] 120 | // [ , , , , , 1, ] 121 | // [ , , 1, , , , ] 122 | // [ , , 1, 1, 1, , ]] 123 | 124 | 125 | // Initialize NUM_NODES wavefronts starting from each vertex in the system 126 | Matrix roots(NUM_NODES, NUM_NODES); 127 | std::vector indices; 128 | for (IndexType idx = 0; idx < NUM_NODES; ++idx) 129 | { 130 | indices.push_back(idx); 131 | } 132 | roots.build(indices, indices, std::vector(NUM_NODES, 1)); 133 | 134 | // Perform NUM_NODES traversals simultaneously 135 | Matrix levels(NUM_NODES, NUM_NODES); 136 | bfs_level_masked(graph, roots, levels); 137 | 138 | print_matrix(std::cout, levels, "Levels"); 139 | // Outputs: 140 | // Levels: structural zero = 0 141 | // [[1, 2, 3, 2, 3, 4, 3] 142 | // [4, 1, 3, 3, 2, 3, 2] 143 | // [ , , 1, , , 2, ] 144 | // [2, 3, 2, 1, 3, 3, 2] 145 | // [ , , 3, , 1, 2, ] 146 | // [ , , 2, , , 1, ] 147 | // [3, 4, 2, 2, 2, 3, 1]] 148 | 149 | return 0; 150 | } 151 | -------------------------------------------------------------------------------- /src/demo/mxm_homework.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | using namespace grb; 35 | 36 | //**************************************************************************** 37 | int main(int, char**) 38 | { 39 | // syntatic sugar 40 | using ScalarType = double; 41 | 42 | IndexType const NUM_ROWS = 3; 43 | IndexType const NUM_COLS = 3; 44 | 45 | // Note: size of dimensions require at ccnstruction 46 | Matrix a(NUM_ROWS, NUM_COLS); 47 | Matrix b(NUM_ROWS, NUM_COLS); 48 | Matrix c(NUM_ROWS, NUM_COLS); 49 | 50 | // initialize matrices 51 | IndexArrayType i = {0, 1, 2}; 52 | IndexArrayType j = {0, 1, 2}; 53 | std::vector v = {1., 1., 1.}; 54 | 55 | a.build(i.begin(), j.begin(), v.begin(), i.size()); 56 | b.build(i.begin(), j.begin(), v.begin(), i.size()); 57 | 58 | print_matrix(std::cout, a, "Matrix A"); 59 | print_matrix(std::cout, b, "Matrix B"); 60 | 61 | // matrix multiply (default parameter values used for some) 62 | mxm(c, NoMask(), NoAccumulate(), ArithmeticSemiring(), a, b); 63 | 64 | print_matrix(std::cout, c, "A +.* B"); 65 | 66 | // extract the results: nvals() method tells us how big 67 | IndexType nvals = c.nvals(); 68 | IndexArrayType rows(nvals), cols(nvals); 69 | std::vector result(nvals); 70 | 71 | c.extractTuples(rows, cols, result); 72 | 73 | IndexArrayType i_ans = {0, 1, 2}; 74 | IndexArrayType j_ans = {0, 1, 2}; 75 | std::vector v_ans = {1., 1., 1.}; 76 | 77 | bool success = true; 78 | for (IndexType ix = 0; ix < result.size(); ++ix) 79 | { 80 | // Note: no semantics defined for extractTuples regarding the 81 | // order of returned values, so using an O(N^2) approach 82 | // without sorting: 83 | bool found = false; 84 | for (IndexType iy = 0; iy < v_ans.size(); ++iy) 85 | { 86 | if ((i_ans[iy] == rows[ix]) && (j_ans[iy] == cols[ix])) 87 | { 88 | std::cout << "Found result: result index, answer index = " 89 | << ix << ", " << iy 90 | << ": res(" << rows[ix] << "," << cols[ix] 91 | << ") ?= ans(" << i_ans[iy] << "," << j_ans[iy] << "), " 92 | << result[ix] << " ?= " << v_ans[iy] << std::endl; 93 | found = true; 94 | if (v_ans[iy] != result[ix]) 95 | { 96 | std::cerr << "ERROR" << std::endl; 97 | success = false; 98 | } 99 | break; 100 | } 101 | } 102 | if (!found) 103 | { 104 | success = false; 105 | } 106 | } 107 | 108 | return (success ? 0 : 1); 109 | } 110 | -------------------------------------------------------------------------------- /src/demo/peer_pressure_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | using namespace grb; 34 | 35 | //**************************************************************************** 36 | int main() 37 | { 38 | // {{1, 0, 1, 1, 0, 0, 1, 0}, 39 | // {0, 1, 1, 1, 0, 0, 0, 1}, 40 | // {1, 0, 1, 0, 1, 0, 1, 0}, 41 | // {1, 1, 0, 1, 0, 1, 0, 0}, 42 | // {1, 0, 1, 0, 1, 0, 1, 0}, 43 | // {0, 1, 0, 1, 0, 1, 1, 1}, 44 | // {1, 0, 0, 0, 1, 0, 1, 0}, 45 | // {0, 1, 0, 1, 0, 1, 0, 1}} 46 | 47 | IndexArrayType i1 = {0, 0, 0, 0, 1, 1, 1, 1, 48 | 2, 2, 2, 2, 3, 3, 3, 3, 49 | 4, 4, 4, 4, 5, 5, 5, 5, 5, 50 | 6, 6, 6, 7, 7, 7, 7}; 51 | IndexArrayType j1 = {0, 2, 3, 6, 1, 2, 3, 7, 52 | 0, 2, 4, 6, 0, 1, 3, 5, 53 | 0, 2, 4, 6, 1, 3, 5, 6, 7, 54 | 0, 4, 6, 1, 3, 5, 7}; 55 | std::vector v1(i1.size(), 1.0); 56 | Matrix G_m1(8, 8); 57 | G_m1.build(i1.begin(), j1.begin(), v1.begin(), i1.size()); 58 | 59 | auto ans = algorithms::peer_pressure_cluster(G_m1); 60 | print_matrix(std::cout, ans, "G_m1 cluster matrix"); 61 | 62 | auto clusters = algorithms::get_cluster_assignments(ans); 63 | std::cout << "cluster assignments:"; 64 | for (auto it = clusters.begin(); it != clusters.end(); ++it) 65 | { 66 | std::cout << " " << *it; 67 | } 68 | std::cout << std::endl; 69 | 70 | // {{1, 1, 1, 1, 0}, 71 | // {1, 1, 1, 0, 0}, 72 | // {1, 1, 1, 0, 0}, 73 | // {0, 0, 0, 1, 1}, 74 | // {0, 0, 0, 1, 1}} 75 | 76 | IndexArrayType i2 = {0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4}; 77 | IndexArrayType j2 = {0, 1, 2, 3, 0, 1, 2, 0, 1, 2, 3, 4, 3, 4}; 78 | std::vector v2(i2.size(), 1.0); 79 | Matrix G_m2(5, 5); 80 | G_m2.build(i2.begin(), j2.begin(), v2.begin(), i2.size()); 81 | 82 | auto ans2 = algorithms::peer_pressure_cluster(G_m2); 83 | print_matrix(std::cout, ans2, "G_m2 cluster matrix"); 84 | 85 | auto clusters2 = algorithms::get_cluster_assignments(ans2); 86 | std::cout << "cluster assignments:"; 87 | for (auto it = clusters2.begin(); it != clusters2.end(); ++it) 88 | { 89 | std::cout << " " << *it; 90 | } 91 | std::cout << std::endl; 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /src/demo/peer_pressure_karate_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | grb::IndexType const NUM_NODES = 34; 35 | 36 | grb::IndexArrayType i = { 37 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 38 | 1,1,1,1,1,1,1,1,1, 39 | 2,2,2,2,2,2,2,2,2,2, 40 | 3,3,3,3,3,3, 41 | 4,4,4, 42 | 5,5,5,5, 43 | 6,6,6,6, 44 | 7,7,7,7, 45 | 8,8,8,8,8, 46 | 9,9, 47 | 10,10,10, 48 | 11, 49 | 12,12, 50 | 13,13,13,13,13, 51 | 14,14, 52 | 15,15, 53 | 16,16, 54 | 17,17, 55 | 18,18, 56 | 19,19,19, 57 | 20,20, 58 | 21,21, 59 | 22,22, 60 | 23,23,23,23,23, 61 | 24,24,24, 62 | 25,25,25, 63 | 26,26, 64 | 27,27,27,27, 65 | 28,28,28, 66 | 29,29,29,29, 67 | 30,30,30,30, 68 | 31,31,31,31,31, 69 | 32,32,32,32,32,32,32,32,32,32,32,32, 70 | 33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33}; 71 | 72 | grb::IndexArrayType j = { 73 | 1,2,3,4,5,6,7,8,10,11,12,13,17,19,21,31, //1,2,3,4,5,6,7,8,10,11,12,13,19,21,23,31, 74 | 0,2,3,7,13,17,19,21,30, 75 | 0,1,3,7,8,9,13,27,28,32, 76 | 0,1,2,7,12,13, 77 | 0,6,10, 78 | 0,6,10,16, 79 | 0,4,5,16, 80 | 0,1,2,3, 81 | 0,2,30,32,33, 82 | 2,33, 83 | 0,4,5, 84 | 0, 85 | 0,3, 86 | 0,1,2,3,33, 87 | 32,33, 88 | 32,33, 89 | 5,6, 90 | 0,1, 91 | 32,33, 92 | 0,1,33, 93 | 32,33, 94 | 0,1, 95 | 32,33, 96 | 25,27,29,32,33, 97 | 25,27,31, 98 | 23,24,31, 99 | 29,33, 100 | 2,23,24,33, 101 | 2,31,33, 102 | 23,26,32,33, 103 | 1,8,32,33, 104 | 0,24,25,32,33, //0,24,25,28,32,33, 105 | 2,8,14,15,18,20,22,23,29,30,31,33, 106 | 8,9,13,14,15,18,19,20,22,23,26,27,28,29,30,31,32}; 107 | 108 | //**************************************************************************** 109 | int main(int, char**) 110 | { 111 | grb::Matrix A_karate(NUM_NODES, NUM_NODES); 112 | grb::Matrix G_karate(NUM_NODES, NUM_NODES); 113 | if (i.size() != j.size()) 114 | { 115 | std::cerr << "Index arrays are not the same size: " << i.size() 116 | << " != " << j.size() << std::endl; 117 | return -1; 118 | } 119 | 120 | std::vector weights(i.size(), 1.0); 121 | G_karate.build(i.begin(), j.begin(), weights.begin(), i.size()); 122 | 123 | auto Clusters = 124 | grb::scaled_identity>(NUM_NODES); 125 | 126 | // Add self-loops to graph 127 | grb::eWiseAdd(A_karate, 128 | grb::NoMask(), grb::NoAccumulate(), 129 | grb::Plus(), 130 | G_karate, Clusters); 131 | 132 | algorithms::peer_pressure_cluster_v2(A_karate, Clusters, 100); 133 | 134 | auto clusters = algorithms::get_cluster_assignments(Clusters); 135 | std::cout << "p.p. cluster assignments (no normalization): "; 136 | for (auto it = clusters.begin(); it != clusters.end(); ++it) 137 | { 138 | std::cout << " " << *it; 139 | } 140 | std::cout << std::endl; 141 | 142 | auto Clusters2 = grb::scaled_identity>(NUM_NODES); 143 | 144 | algorithms::peer_pressure_cluster(A_karate, Clusters2, 100); 145 | 146 | auto clusters2 = algorithms::get_cluster_assignments(Clusters2); 147 | std::cout << "cluster assignments (with normalization): "; 148 | for (auto it = clusters2.begin(); it != clusters2.end(); ++it) 149 | { 150 | std::cout << " " << *it; 151 | } 152 | std::cout << std::endl; 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /src/demo/simulated_blockmodel_graph_50_nodes.tsv: -------------------------------------------------------------------------------- 1 | 1 14 1 2 | 1 27 1 3 | 1 36 1 4 | 1 17 1 5 | 1 35 1 6 | 2 12 1 7 | 2 3 1 8 | 2 14 1 9 | 2 28 1 10 | 2 45 1 11 | 2 32 1 12 | 3 15 1 13 | 3 48 1 14 | 3 18 1 15 | 3 6 1 16 | 4 45 1 17 | 4 23 1 18 | 4 20 1 19 | 4 36 1 20 | 4 7 1 21 | 4 35 1 22 | 4 24 1 23 | 4 22 1 24 | 5 26 1 25 | 5 4 1 26 | 5 25 1 27 | 5 30 1 28 | 6 31 1 29 | 6 32 1 30 | 6 48 1 31 | 6 13 1 32 | 7 24 1 33 | 7 40 1 34 | 7 1 1 35 | 7 45 1 36 | 8 9 1 37 | 8 15 1 38 | 8 14 1 39 | 8 41 1 40 | 8 16 1 41 | 9 39 1 42 | 9 32 1 43 | 9 44 1 44 | 9 3 1 45 | 9 43 1 46 | 9 8 1 47 | 10 26 1 48 | 10 27 1 49 | 10 2 1 50 | 10 21 1 51 | 10 16 1 52 | 10 32 1 53 | 10 14 1 54 | 10 50 1 55 | 11 45 1 56 | 11 24 1 57 | 11 36 1 58 | 11 42 1 59 | 12 35 1 60 | 12 3 1 61 | 12 21 1 62 | 12 48 1 63 | 12 37 1 64 | 12 8 1 65 | 12 15 1 66 | 12 18 1 67 | 13 27 1 68 | 13 28 1 69 | 13 23 1 70 | 13 12 1 71 | 13 14 1 72 | 13 37 1 73 | 14 15 1 74 | 14 21 1 75 | 14 33 1 76 | 14 6 1 77 | 15 31 1 78 | 15 23 1 79 | 15 50 1 80 | 15 32 1 81 | 15 37 1 82 | 15 11 1 83 | 15 48 1 84 | 15 3 1 85 | 15 22 1 86 | 16 32 1 87 | 16 3 1 88 | 16 14 1 89 | 16 33 1 90 | 16 25 1 91 | 16 21 1 92 | 16 26 1 93 | 16 31 1 94 | 16 2 1 95 | 16 28 1 96 | 16 50 1 97 | 16 4 1 98 | 16 37 1 99 | 16 11 1 100 | 17 14 1 101 | 17 7 1 102 | 17 40 1 103 | 17 36 1 104 | 17 45 1 105 | 17 41 1 106 | 17 18 1 107 | 18 15 1 108 | 18 8 1 109 | 18 2 1 110 | 18 5 1 111 | 19 6 1 112 | 19 5 1 113 | 19 29 1 114 | 19 39 1 115 | 19 48 1 116 | 19 46 1 117 | 19 37 1 118 | 19 12 1 119 | 20 46 1 120 | 20 36 1 121 | 20 35 1 122 | 20 39 1 123 | 20 24 1 124 | 20 1 1 125 | 20 11 1 126 | 20 41 1 127 | 20 42 1 128 | 20 40 1 129 | 20 34 1 130 | 20 17 1 131 | 20 27 1 132 | 21 14 1 133 | 21 13 1 134 | 21 2 1 135 | 21 3 1 136 | 21 20 1 137 | 21 50 1 138 | 22 35 1 139 | 22 48 1 140 | 22 7 1 141 | 22 49 1 142 | 22 1 1 143 | 22 39 1 144 | 23 47 1 145 | 23 19 1 146 | 23 14 1 147 | 23 48 1 148 | 23 34 1 149 | 24 12 1 150 | 24 30 1 151 | 24 20 1 152 | 24 31 1 153 | 25 19 1 154 | 25 34 1 155 | 25 30 1 156 | 25 48 1 157 | 26 6 1 158 | 26 50 1 159 | 26 14 1 160 | 26 15 1 161 | 26 12 1 162 | 26 10 1 163 | 26 34 1 164 | 26 37 1 165 | 26 31 1 166 | 26 32 1 167 | 26 13 1 168 | 27 37 1 169 | 27 40 1 170 | 27 20 1 171 | 27 7 1 172 | 27 32 1 173 | 27 15 1 174 | 27 34 1 175 | 27 4 1 176 | 28 31 1 177 | 28 5 1 178 | 28 10 1 179 | 28 50 1 180 | 29 46 1 181 | 29 34 1 182 | 29 30 1 183 | 29 48 1 184 | 30 29 1 185 | 30 25 1 186 | 30 5 1 187 | 30 34 1 188 | 30 43 1 189 | 31 32 1 190 | 31 33 1 191 | 31 8 1 192 | 31 13 1 193 | 31 15 1 194 | 31 16 1 195 | 32 8 1 196 | 32 15 1 197 | 32 26 1 198 | 32 27 1 199 | 32 14 1 200 | 32 43 1 201 | 32 25 1 202 | 33 12 1 203 | 33 32 1 204 | 33 16 1 205 | 33 3 1 206 | 33 8 1 207 | 34 44 1 208 | 34 9 1 209 | 34 47 1 210 | 34 5 1 211 | 34 29 1 212 | 34 49 1 213 | 34 25 1 214 | 35 38 1 215 | 35 36 1 216 | 35 15 1 217 | 35 41 1 218 | 35 4 1 219 | 35 27 1 220 | 35 11 1 221 | 35 42 1 222 | 35 20 1 223 | 36 11 1 224 | 36 35 1 225 | 36 22 1 226 | 36 42 1 227 | 36 28 1 228 | 36 17 1 229 | 36 31 1 230 | 36 20 1 231 | 36 27 1 232 | 36 47 1 233 | 37 38 1 234 | 37 14 1 235 | 37 6 1 236 | 37 26 1 237 | 37 18 1 238 | 37 8 1 239 | 37 28 1 240 | 37 21 1 241 | 37 10 1 242 | 37 3 1 243 | 37 33 1 244 | 38 25 1 245 | 38 49 1 246 | 38 34 1 247 | 38 39 1 248 | 38 9 1 249 | 38 19 1 250 | 38 48 1 251 | 38 30 1 252 | 39 38 1 253 | 39 19 1 254 | 39 48 1 255 | 39 25 1 256 | 39 34 1 257 | 39 49 1 258 | 39 23 1 259 | 40 35 1 260 | 40 8 1 261 | 40 41 1 262 | 40 36 1 263 | 40 20 1 264 | 40 29 1 265 | 40 1 1 266 | 41 35 1 267 | 41 22 1 268 | 41 36 1 269 | 41 17 1 270 | 41 48 1 271 | 42 1 1 272 | 42 30 1 273 | 42 24 1 274 | 42 36 1 275 | 43 49 1 276 | 43 34 1 277 | 43 9 1 278 | 43 25 1 279 | 43 48 1 280 | 44 47 1 281 | 44 26 1 282 | 44 14 1 283 | 44 46 1 284 | 44 39 1 285 | 44 43 1 286 | 44 5 1 287 | 44 29 1 288 | 44 30 1 289 | 45 1 1 290 | 45 24 1 291 | 45 3 1 292 | 45 41 1 293 | 46 34 1 294 | 46 25 1 295 | 46 49 1 296 | 46 27 1 297 | 47 22 1 298 | 47 44 1 299 | 47 48 1 300 | 47 43 1 301 | 48 19 1 302 | 48 27 1 303 | 48 28 1 304 | 48 25 1 305 | 48 38 1 306 | 48 33 1 307 | 48 5 1 308 | 48 13 1 309 | 49 19 1 310 | 49 23 1 311 | 49 44 1 312 | 49 26 1 313 | 50 14 1 314 | 50 33 1 315 | 50 10 1 316 | 50 44 1 317 | 50 8 1 318 | 50 31 1 319 | 50 22 1 320 | -------------------------------------------------------------------------------- /src/demo/simulated_blockmodel_graph_50_nodes_truePartition.tsv: -------------------------------------------------------------------------------- 1 | 1 2 2 | 2 1 3 | 3 1 4 | 4 2 5 | 5 3 6 | 6 1 7 | 7 2 8 | 8 1 9 | 9 3 10 | 10 1 11 | 11 2 12 | 12 1 13 | 13 1 14 | 14 1 15 | 15 1 16 | 16 1 17 | 17 2 18 | 18 1 19 | 19 3 20 | 20 2 21 | 21 1 22 | 22 2 23 | 23 3 24 | 24 2 25 | 25 3 26 | 26 1 27 | 27 2 28 | 28 1 29 | 29 3 30 | 30 3 31 | 31 1 32 | 32 1 33 | 33 1 34 | 34 3 35 | 35 2 36 | 36 2 37 | 37 1 38 | 38 3 39 | 39 3 40 | 40 2 41 | 41 2 42 | 42 2 43 | 43 3 44 | 44 3 45 | 45 2 46 | 46 3 47 | 47 3 48 | 48 3 49 | 49 3 50 | 50 1 51 | -------------------------------------------------------------------------------- /src/demo/sssp_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | template 35 | void run_demo() 36 | { 37 | // FA Tech Note graph 38 | // 39 | // {-, -, -, 1, -, -, -, -, -}, 40 | // {-, -, -, 1, -, -, 1, -, -}, 41 | // {-, -, -, -, 1, 1, 1, -, 1}, 42 | // {1, 1, -, -, 1, -, 1, -, -}, 43 | // {-, -, 1, 1, -, -, -, -, 1}, 44 | // {-, -, 1, -, -, -, -, -, -}, 45 | // {-, 1, 1, 1, -, -, -, -, -}, 46 | // {-, -, -, -, -, -, -, -, -}, 47 | // {-, -, 1, -, 1, -, -, -, -}; 48 | 49 | grb::IndexType const NUM_NODES = 9; 50 | grb::IndexArrayType i = {0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 51 | 4, 4, 4, 5, 6, 6, 6, 8, 8}; 52 | grb::IndexArrayType j = {3, 3, 6, 4, 5, 6, 8, 0, 1, 4, 6, 53 | 2, 3, 8, 2, 1, 2, 3, 2, 4}; 54 | std::vector v(i.size(), 1); 55 | 56 | grb::Matrix G_tn(NUM_NODES, NUM_NODES); 57 | 58 | G_tn.build(i.begin(), j.begin(), v.begin(), i.size()); 59 | grb::print_matrix(std::cout, G_tn, "Graph"); 60 | 61 | // compute one shortest paths 62 | grb::Vector path(NUM_NODES); 63 | path.setElement(0, 0); 64 | grb::print_vector(std::cout, path, "Source"); 65 | algorithms::sssp(G_tn, path); 66 | grb::print_vector(std::cout, path, "single SSSP results"); 67 | 68 | // compute all shortest paths 69 | auto paths = grb::scaled_identity>(NUM_NODES, 0); 70 | grb::print_matrix(std::cout, paths, "Sources"); 71 | algorithms::batch_sssp(G_tn, paths); 72 | grb::print_matrix(std::cout, paths, "batch SSSP results"); 73 | } 74 | 75 | //**************************************************************************** 76 | int main() 77 | { 78 | std::cout << "ScalarType = double:" << std::endl; 79 | run_demo(); 80 | 81 | std::cout << "ScalarType = unsigned int" << std::endl; 82 | run_demo(); 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /src/demo/triangle_count_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define GRAPHBLAS_DEBUG 1 33 | 34 | #include 35 | #include 36 | #include "Timer.hpp" 37 | 38 | //**************************************************************************** 39 | int main(int argc, char **argv) 40 | { 41 | if (argc < 2) 42 | { 43 | std::cerr << "ERROR: too few arguments." << std::endl; 44 | exit(1); 45 | } 46 | 47 | // Read the edgelist and create the tuple arrays 48 | std::string pathname(argv[1]); 49 | 50 | 51 | Timer my_timer; 52 | 53 | grb::IndexArrayType iL, iU, iA; 54 | grb::IndexArrayType jL, jU, jA; 55 | uint64_t num_rows = 0; 56 | uint64_t max_id = 0; 57 | uint64_t src, dst; 58 | 59 | my_timer.start(); 60 | { 61 | std::ifstream infile(pathname); 62 | while (infile) 63 | { 64 | infile >> src >> dst; 65 | //std::cout << "Read: " << src << ", " << dst << std::endl; 66 | if (src > max_id) max_id = src; 67 | if (dst > max_id) max_id = dst; 68 | 69 | if (src < dst) 70 | { 71 | iA.push_back(src); 72 | jA.push_back(dst); 73 | 74 | iU.push_back(src); 75 | jU.push_back(dst); 76 | } 77 | else if (dst < src) 78 | { 79 | iA.push_back(src); 80 | jA.push_back(dst); 81 | 82 | iL.push_back(src); 83 | jL.push_back(dst); 84 | } 85 | // else ignore self loops 86 | 87 | ++num_rows; 88 | } 89 | } 90 | my_timer.stop(); 91 | std::cout << "Elapsed read time: " << my_timer.elapsed() << " usec." << std::endl; 92 | 93 | std::cout << "Read " << num_rows << " rows." << std::endl; 94 | std::cout << "#Nodes = " << (max_id + 1) << std::endl; 95 | 96 | // sort the 97 | using DegIdx = std::tuple; 98 | my_timer.start(); 99 | std::vector degrees(max_id + 1); 100 | for (grb::IndexType idx = 0; idx <= max_id; ++idx) 101 | { 102 | degrees[idx] = {0UL, idx}; 103 | } 104 | 105 | { 106 | std::ifstream infile(pathname); 107 | while (infile) 108 | { 109 | infile >> src >> dst; 110 | if (src != dst) 111 | { 112 | std::get<0>(degrees[src]) += 1; 113 | } 114 | } 115 | } 116 | 117 | std::sort(degrees.begin(), degrees.end(), 118 | [](DegIdx a, DegIdx b) { return std::get<0>(b) < std::get<0>(a); }); 119 | 120 | //relabel 121 | for (auto &idx : iA) { idx = std::get<1>(degrees[idx]); } 122 | for (auto &idx : jA) { idx = std::get<1>(degrees[idx]); } 123 | for (auto &idx : iL) { idx = std::get<1>(degrees[idx]); } 124 | for (auto &idx : jL) { idx = std::get<1>(degrees[idx]); } 125 | for (auto &idx : iU) { idx = std::get<1>(degrees[idx]); } 126 | for (auto &idx : jU) { idx = std::get<1>(degrees[idx]); } 127 | 128 | my_timer.stop(); 129 | std::cout << "Elapsed sort/relabel time: " << my_timer.elapsed() << " usec." << std::endl; 130 | 131 | grb::IndexType idx(0); 132 | for (auto&& row : degrees) 133 | { 134 | std::cout << idx << " <-- " << std::get<1>(row) 135 | << ": deg = " << std::get<0>(row) << std::endl; 136 | idx++; 137 | } 138 | 139 | grb::IndexType NUM_NODES(max_id + 1); 140 | using T = int32_t; 141 | std::vector v(iA.size(), 1); 142 | 143 | /// @todo change scalar type to unsigned int or grb::IndexType 144 | using MatType = grb::Matrix; 145 | 146 | MatType A(NUM_NODES, NUM_NODES); 147 | MatType L(NUM_NODES, NUM_NODES); 148 | MatType U(NUM_NODES, NUM_NODES); 149 | 150 | A.build(iA.begin(), jA.begin(), v.begin(), iA.size()); 151 | L.build(iL.begin(), jL.begin(), v.begin(), iL.size()); 152 | U.build(iU.begin(), jU.begin(), v.begin(), iU.size()); 153 | 154 | std::cout << "Running algorithm(s)..." << std::endl; 155 | T count(0); 156 | 157 | // Perform triangle counting with different algorithms 158 | //=================== 159 | my_timer.start(); 160 | count = algorithms::triangle_count(A); 161 | my_timer.stop(); 162 | 163 | std::cout << "# triangles (L,U=split(A); B=LL'; C=A.*B; #=|C|/2) = " << count << std::endl; 164 | std::cout << "Elapsed time: " << my_timer.elapsed() << " usec." << std::endl; 165 | 166 | //=================== 167 | my_timer.start(); 168 | count = algorithms::triangle_count_masked(L, U); 169 | my_timer.stop(); 170 | 171 | std::cout << "# triangles (C = L +.* U; #=|C|) = " << count << std::endl; 172 | std::cout << "Elapsed time: " << my_timer.elapsed() << " usec." << std::endl; 173 | 174 | //=================== 175 | my_timer.start(); 176 | count = algorithms::triangle_count_masked(L); 177 | my_timer.stop(); 178 | 179 | std::cout << "# triangles (C = L +.* L'; #=|C|) = " << count << std::endl; 180 | std::cout << "Elapsed time: " << my_timer.elapsed() << " usec." << std::endl; 181 | 182 | //=================== 183 | my_timer.start(); 184 | count = algorithms::triangle_count_masked_noT(L); 185 | my_timer.stop(); 186 | 187 | std::cout << "# triangles (C = L +.* L; #=|C|) = " << count << std::endl; 188 | std::cout << "Elapsed time: " << my_timer.elapsed() << " usec." << std::endl; 189 | 190 | //=================== 191 | my_timer.start(); 192 | count = algorithms::triangle_count_newGBTL(L, U); 193 | my_timer.stop(); 194 | 195 | std::cout << "# triangles (B=LU; C=L.*B; #=|C|) = " << count << std::endl; 196 | std::cout << "Elapsed time: " << my_timer.elapsed() << " usec." << std::endl; 197 | 198 | return 0; 199 | } 200 | -------------------------------------------------------------------------------- /src/graphblas/ComplementView.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | //**************************************************************************** 35 | 36 | namespace grb 37 | { 38 | //************************************************************************ 39 | template 40 | class MatrixComplementView 41 | { 42 | public: 43 | using ScalarType = bool; 44 | 45 | MatrixComplementView(MatrixT const &mat) 46 | : m_mat(mat) 47 | { 48 | } 49 | 50 | IndexType nrows() const { return m_mat.nrows(); } 51 | IndexType ncols() const { return m_mat.ncols(); } 52 | 53 | void printInfo(std::ostream &os) const 54 | { 55 | os << "MatrixComplementView of: "; 56 | m_mat.printInfo(os); 57 | } 58 | 59 | friend std::ostream &operator<<(std::ostream &os, 60 | MatrixComplementView const &mat) 61 | { 62 | os << "MatrixComplementView of: "; 63 | os << mat.m_mat; 64 | return os; 65 | } 66 | 67 | MatrixT const &m_mat; 68 | 69 | }; 70 | 71 | //************************************************************************ 72 | template , int> = 0> 74 | decltype(auto) 75 | get_internal_matrix(ViewT const &view) 76 | { 77 | return MatrixComplementView(get_internal_matrix(view.m_mat)); 78 | } 79 | 80 | 81 | //************************************************************************ 82 | //************************************************************************ 83 | 84 | //************************************************************************ 85 | template 86 | class VectorComplementView 87 | { 88 | public: 89 | using ScalarType = bool; 90 | 91 | VectorComplementView(VectorT const &vec) 92 | : m_vec(vec) 93 | { 94 | } 95 | 96 | IndexType size() const { return m_vec.size(); } 97 | 98 | void printInfo(std::ostream &os) const 99 | { 100 | os << "Frontend VectorComplementView of: "; 101 | m_vec.printInfo(os); 102 | } 103 | 104 | friend std::ostream &operator<<(std::ostream &os, 105 | VectorComplementView const &vec) 106 | { 107 | os << "VectorComplementView of: "; 108 | os << vec.m_vec; 109 | return os; 110 | } 111 | 112 | VectorT const &m_vec; 113 | }; 114 | 115 | //************************************************************************ 116 | template , int> = 0> 118 | decltype(auto) 119 | get_internal_vector(ViewT const &view) 120 | { 121 | return VectorComplementView(get_internal_vector(view.m_vec)); 122 | } 123 | 124 | } // end namespace grb 125 | -------------------------------------------------------------------------------- /src/graphblas/StructuralComplementView.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | //**************************************************************************** 35 | 36 | namespace grb 37 | { 38 | //************************************************************************ 39 | template 40 | class MatrixStructuralComplementView 41 | { 42 | public: 43 | using ScalarType = bool; 44 | 45 | MatrixStructuralComplementView(MatrixT const &mat) 46 | : m_mat(mat) 47 | { 48 | } 49 | 50 | IndexType nrows() const { return m_mat.nrows(); } 51 | IndexType ncols() const { return m_mat.ncols(); } 52 | IndexType nvals() const 53 | { 54 | return (m_mat.nrows()*m_mat.ncols() - m_mat.nvals()); 55 | } 56 | 57 | void printInfo(std::ostream &os) const 58 | { 59 | os << "MatrixStructuralComplementView of: "; 60 | m_mat.printInfo(os); 61 | } 62 | 63 | friend std::ostream &operator<<(std::ostream &os, 64 | MatrixStructuralComplementView const &mat) 65 | { 66 | os << "MatrixStructuralComplementView of: "; 67 | os << mat.m_mat; 68 | return os; 69 | } 70 | 71 | MatrixT const &m_mat; 72 | }; 73 | 74 | //************************************************************************ 75 | template , int> = 0> 77 | decltype(auto) 78 | get_internal_matrix(ViewT const &view) 79 | { 80 | return MatrixStructuralComplementView(get_internal_matrix(view.m_mat)); 81 | } 82 | 83 | 84 | //************************************************************************ 85 | //************************************************************************ 86 | 87 | //************************************************************************ 88 | template 89 | class VectorStructuralComplementView 90 | { 91 | public: 92 | using ScalarType = bool; 93 | 94 | VectorStructuralComplementView(VectorT const &vec) 95 | : m_vec(vec) 96 | { 97 | } 98 | 99 | IndexType size() const { return m_vec.size(); } 100 | IndexType nvals() const { return m_vec.size() - m_vec.nvals(); } 101 | 102 | void printInfo(std::ostream &os) const 103 | { 104 | os << "VectorStructuralComplementView of: "; 105 | m_vec.printInfo(os); 106 | } 107 | 108 | friend std::ostream &operator<<(std::ostream &os, 109 | VectorStructuralComplementView const &vec) 110 | { 111 | os << "VectorStructuralComplementView of: "; 112 | os << vec.m_vec; 113 | return os; 114 | } 115 | 116 | VectorT const &m_vec; 117 | }; 118 | 119 | //************************************************************************ 120 | template , int> = 0> 122 | decltype(auto) 123 | get_internal_vector(ViewT const &view) 124 | { 125 | return VectorStructuralComplementView(get_internal_vector(view.m_vec)); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/graphblas/StructureView.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | //**************************************************************************** 35 | 36 | namespace grb 37 | { 38 | //************************************************************************ 39 | template 40 | class MatrixStructureView 41 | { 42 | public: 43 | using ScalarType = bool; 44 | 45 | MatrixStructureView(MatrixT const &mat) 46 | : m_mat(mat) 47 | { 48 | } 49 | 50 | IndexType nrows() const { return m_mat.nrows(); } 51 | IndexType ncols() const { return m_mat.ncols(); } 52 | IndexType nvals() const { return m_mat.nvals(); } 53 | 54 | void printInfo(std::ostream &os) const 55 | { 56 | os << "MatrixStructureView of: "; 57 | m_mat.printInfo(os); 58 | } 59 | 60 | friend std::ostream &operator<<(std::ostream &os, 61 | MatrixStructureView const &mat) 62 | { 63 | os << "MatrixStructureView of: "; 64 | os << mat.m_mat; 65 | return os; 66 | } 67 | 68 | MatrixT const &m_mat; 69 | }; 70 | 71 | //************************************************************************ 72 | template , int> = 0> 74 | decltype(auto) 75 | get_internal_matrix(ViewT const &view) 76 | { 77 | return MatrixStructureView(get_internal_matrix(view.m_mat)); 78 | } 79 | 80 | 81 | //************************************************************************ 82 | //************************************************************************ 83 | 84 | //************************************************************************ 85 | template 86 | class VectorStructureView 87 | { 88 | public: 89 | using ScalarType = bool; 90 | 91 | VectorStructureView(VectorT const &vec) 92 | : m_vec(vec) 93 | { 94 | } 95 | 96 | IndexType size() const { return m_vec.size(); } 97 | IndexType nvals() const { return m_vec.nvals(); } 98 | 99 | void printInfo(std::ostream &os) const 100 | { 101 | os << "VectorStructureView of: "; 102 | m_vec.printInfo(os); 103 | } 104 | 105 | friend std::ostream &operator<<(std::ostream &os, 106 | VectorStructureView const &vec) 107 | { 108 | os << "VectorStructureView of: "; 109 | os << vec.m_vec; 110 | return os; 111 | } 112 | 113 | VectorT const &m_vec; 114 | }; 115 | 116 | //************************************************************************ 117 | template , int> = 0> 119 | decltype(auto) 120 | get_internal_vector(ViewT const &view) 121 | { 122 | return VectorStructureView(get_internal_vector(view.m_vec)); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/graphblas/TransposeView.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #define GB_INCLUDE_BACKEND_TRANSPOSE_VIEW 1 34 | #include 35 | 36 | //**************************************************************************** 37 | //**************************************************************************** 38 | 39 | 40 | namespace grb 41 | { //************************************************************************ 42 | template 43 | class TransposeView 44 | { 45 | public: 46 | using ScalarType = typename MatrixT::ScalarType; 47 | 48 | TransposeView(MatrixT const &mat) 49 | : m_mat(mat) 50 | { 51 | } 52 | 53 | IndexType nrows() const { return m_mat.ncols(); } 54 | IndexType ncols() const { return m_mat.nrows(); } 55 | 56 | void printInfo(std::ostream &os) const 57 | { 58 | os << "TransposeView of: "; 59 | m_mat.printInfo(os); 60 | } 61 | 62 | friend std::ostream &operator<<(std::ostream &os, 63 | TransposeView const &mat) 64 | { 65 | os << "TransposeView of: "; 66 | os << mat.m_mat; 67 | return os; 68 | } 69 | 70 | MatrixT const &m_mat; 71 | 72 | }; 73 | 74 | //************************************************************************ 75 | template , int> = 0> 77 | decltype(auto) 78 | get_internal_matrix(ViewT const &view) 79 | { 80 | return TransposeView(get_internal_matrix(view.m_mat)); 81 | } 82 | } // end namespace grb 83 | -------------------------------------------------------------------------------- /src/graphblas/detail/config.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | /// @todo: reimplement the GPU platform someday or adopt GraphBLAST 29 | 30 | #pragma once 31 | 32 | #if !defined(__CUDACC__) 33 | #ifndef __host__ 34 | #define __host__ 35 | #endif // __host__ 36 | 37 | #ifndef __device__ 38 | #define __device__ 39 | #endif // __device__ 40 | 41 | #endif // __CUDACC__ 42 | -------------------------------------------------------------------------------- /src/graphblas/detail/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | // Basic debugging 33 | #if GRAPHBLAS_LOGGING_LEVEL > 0 34 | 35 | #define GRB_LOG(x) do { std::cout << "GRB " << x << std::endl; } while(0) 36 | #define GRB_LOG_FN_BEGIN(x) do { std::cout << "GRB >>> Begin: " << x << std::endl; } while(0) 37 | #define GRB_LOG_FN_END(x) do { std::cout << "GRB <<< End: " << x << std::endl; } while(0) 38 | 39 | // Verbose debugging 40 | #if GRAPHBLAS_LOGGING_LEVEL > 1 41 | 42 | #define GRB_LOG_VERBOSE(x) do { std::cout << "GRB --- " << x << std::endl; } while(0) 43 | #define GRB_LOG_VERBOSE_ACCUM(x) do { std::cout << "GRB --- accum: " << typeid(x).name() << std::endl; } while(0) 44 | #define GRB_LOG_VERBOSE_OP(x) do { std::cout << "GRB --- op: " << typeid(x).name() << std::endl; } while(0) 45 | #define GRB_LOG_VERBOSE_OUTP(x) do { std::cout << "GRB --- outp: " << ((x == grb::MERGE) ? "MERGE" : "REPLACE") << std::endl; } while(0) 46 | 47 | #else 48 | 49 | #define GRB_LOG_VERBOSE(x) 50 | #define GRB_LOG_VERBOSE_ACCUM(x) 51 | #define GRB_LOG_VERBOSE_OP(x) 52 | #define GRB_LOG_VERBOSE_OUTP(x) 53 | 54 | #endif 55 | 56 | #else 57 | 58 | #define GRB_LOG(x) 59 | #define GRB_LOG_FN_BEGIN(x) 60 | #define GRB_LOG_FN_END(x) 61 | 62 | #define GRB_LOG_VERBOSE(x) 63 | #define GRB_LOG_VERBOSE_ACCUM(x) 64 | #define GRB_LOG_VERBOSE_OP(x) 65 | #define GRB_LOG_VERBOSE_OUTP(x) 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/graphblas/detail/matrix_tags.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | //**************************************************************************** 31 | 32 | namespace grb 33 | { 34 | // The default matrix is sparse and directed, and the default vector is sparse, 35 | // so we need tags that modify that 36 | struct DirectedMatrixTag {}; 37 | struct UndirectedMatrixTag {}; 38 | struct DenseTag {}; 39 | struct SparseTag {}; 40 | 41 | namespace detail 42 | { 43 | // add category tags in the detail namespace 44 | struct SparsenessCategoryTag {}; 45 | struct DirectednessCategoryTag {}; 46 | struct NullTag {}; 47 | } //end detail 48 | }//end grb 49 | 50 | //**************************************************************************** 51 | -------------------------------------------------------------------------------- /src/graphblas/detail/param_unpack.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | // matrix tags should be strictly internal 30 | #include "matrix_tags.hpp" 31 | 32 | #define GB_INCLUDE_BACKEND_MATRIX 1 33 | #define GB_INCLUDE_BACKEND_VECTOR 1 34 | #include 35 | 36 | //this file contains the variadic template parameters unpacking utility. 37 | 38 | //**************************************************************************** 39 | //**************************************************************************** 40 | 41 | namespace grb 42 | { 43 | namespace detail 44 | { 45 | 46 | // Substitute template to decide if a tag goes into a given slot 47 | template 48 | struct substitute { 49 | using type = TagCategory; 50 | }; 51 | 52 | 53 | template<> 54 | struct substitute { 55 | using type = DenseTag; 56 | }; 57 | 58 | template<> 59 | struct substitute { 60 | using type = SparseTag; 61 | }; 62 | 63 | template<> 64 | struct substitute { 65 | using type = UndirectedMatrixTag; 66 | }; 67 | 68 | template<> 69 | struct substitute { 70 | using type = DirectedMatrixTag; 71 | }; 72 | 73 | template<> 74 | struct substitute { 75 | //default values 76 | using type = DirectedMatrixTag; // default directedness 77 | }; 78 | 79 | template<> 80 | struct substitute { 81 | using type = SparseTag; // default sparseness 82 | }; 83 | 84 | 85 | // hidden part in the frontend (detail namespace somewhere) to unroll 86 | // template parameter pack 87 | 88 | struct matrix_generator { 89 | // recursive call: shaves off one of the tags and puts it in the right 90 | // place (no error checking yet) 91 | template 93 | struct result { 94 | using type = typename result::type, 96 | typename detail::substitute::type, 97 | Tags... >::type; 98 | }; 99 | 100 | //null tag shortcut: 101 | template 102 | struct result 103 | { 104 | using type = typename backend::Matrix::type, 106 | typename detail::substitute::type >; 107 | }; 108 | 109 | // base case returns the matrix from the backend 110 | template 111 | struct result 112 | { 113 | using type = typename backend::Matrix::type, 115 | typename detail::substitute::type > ; 116 | }; 117 | }; 118 | 119 | /// @todo remove directedness from the vector generator 120 | struct vector_generator { 121 | // recursive call: shaves off one of the tags and puts it in the right 122 | // place (no error checking yet) 123 | template 125 | struct result { 126 | using type = typename result::type, 128 | Tags... >::type; 129 | }; 130 | 131 | //null tag shortcut: 132 | template 133 | struct result 134 | { 135 | using type = typename backend::Vector::type >; 137 | }; 138 | 139 | // base case returns the vector from the backend 140 | template 141 | struct result 142 | { 143 | using type = typename backend::Vector::type > ; 145 | }; 146 | }; 147 | 148 | }//end detail 149 | } 150 | -------------------------------------------------------------------------------- /src/graphblas/exceptions.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grb 38 | { 39 | //************************************************************************ 40 | // Execution Errors, Table 2.5(b) of Spec version 1.0.2 41 | //************************************************************************ 42 | 43 | // out of memory handled by language 44 | 45 | //************************************************************************ 46 | class IndexOutOfBoundsException : public std::exception 47 | { 48 | public: 49 | IndexOutOfBoundsException(std::string const &msg) 50 | : m_message(msg) {} 51 | 52 | IndexOutOfBoundsException() {} 53 | 54 | private: 55 | const char* what() const throw() 56 | { 57 | return ("IndexOutOfBoundsException: " + m_message).c_str(); 58 | } 59 | 60 | std::string m_message; 61 | }; 62 | 63 | //************************************************************************ 64 | class PanicException : public std::exception 65 | { 66 | public: 67 | PanicException(std::string const &msg) 68 | : m_message(msg) {} 69 | 70 | PanicException() {} 71 | 72 | private: 73 | const char* what() const throw() 74 | { 75 | return ("PanicException: " + m_message).c_str(); 76 | } 77 | 78 | std::string m_message; 79 | }; 80 | 81 | //************************************************************************ 82 | // API Errors, Table 2.5(a) of Spec version 1.0.2 83 | //************************************************************************ 84 | 85 | //************************************************************************ 86 | class InvalidValueException : public std::exception 87 | { 88 | public: 89 | InvalidValueException(std::string const &msg) 90 | : m_message(msg) {} 91 | 92 | InvalidValueException() {} 93 | 94 | private: 95 | const char* what() const throw() 96 | { 97 | return ("InvalidValueException: " + m_message).c_str(); 98 | } 99 | 100 | std::string m_message; 101 | }; 102 | 103 | //************************************************************************ 104 | class InvalidIndexException : public std::exception 105 | { 106 | public: 107 | InvalidIndexException(std::string const &msg) 108 | : m_message(msg) {} 109 | 110 | InvalidIndexException() {} 111 | 112 | private: 113 | const char* what() const throw() 114 | { 115 | return ("InvalidIndexException: " + m_message).c_str(); 116 | } 117 | 118 | std::string m_message; 119 | }; 120 | 121 | //************************************************************************ 122 | class DimensionException : public std::exception 123 | { 124 | public: 125 | DimensionException(std::string const &msg) 126 | : m_message(msg) 127 | { 128 | GRB_LOG_VERBOSE("!!! DimensionException: " << msg); 129 | } 130 | 131 | DimensionException(){} 132 | 133 | private: 134 | const char* what() const throw() 135 | { 136 | return ("DimensionException: " + m_message).c_str(); 137 | } 138 | 139 | std::string m_message; 140 | }; 141 | 142 | //************************************************************************ 143 | class OutputNotEmptyException : public std::exception 144 | { 145 | public: 146 | OutputNotEmptyException(std::string const &msg) 147 | : m_message(msg) 148 | { 149 | GRB_LOG_VERBOSE("!!! OutputNotEmptyException: " << msg); 150 | } 151 | 152 | OutputNotEmptyException(){} 153 | 154 | private: 155 | const char* what() const throw() 156 | { 157 | return ("OutputNotEmptyException: " + m_message).c_str(); 158 | } 159 | 160 | std::string m_message; 161 | }; 162 | 163 | //************************************************************************ 164 | class NoValueException : public std::exception 165 | { 166 | public: 167 | NoValueException(std::string const &msg) 168 | : m_message(msg) {} 169 | 170 | NoValueException() {} 171 | 172 | private: 173 | const char* what() const throw() 174 | { 175 | return ("NoValueException: " + m_message).c_str(); 176 | } 177 | 178 | std::string m_message; 179 | }; 180 | } 181 | -------------------------------------------------------------------------------- /src/graphblas/graphblas.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | // C API Version equivalents 33 | #define GRB_VERSION 1 34 | #define GRB_SUBVERSION 3 35 | 36 | namespace grb 37 | { 38 | auto getVersion() 39 | { 40 | return std::make_tuple(static_cast(GRB_VERSION), 41 | static_cast(GRB_SUBVERSION)); 42 | } 43 | } 44 | 45 | #include 46 | 47 | #include 48 | #include 49 | 50 | #include 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | #include 61 | 62 | #define GB_INCLUDE_BACKEND_ALL 1 63 | #include 64 | -------------------------------------------------------------------------------- /src/graphblas/platforms/README_backend.txt: -------------------------------------------------------------------------------- 1 | Each subdirectory in this (system) directory, contains the backend code for 2 | one platform. The name of the subdirectory is the name of the platform used 3 | when configuring the build. Note that only one backend platform can be 4 | configured and compiled at a time. 5 | 6 | Within each platform directory, a backend_include.hpp file should be created. 7 | It should be based on the template in this directory 8 | (backend_include_template.hpp). It should specify which include files within 9 | the backend directory contain the declarations for various classes and 10 | functions needed by the frontend code. Comments in the template header file 11 | provide more information about what to specify: 12 | 13 | 14 | 1. Global search and replace GB_BACKEND_NAME with the name of the platform 15 | directory. 16 | 17 | 2. Use GB_INCLUDE_BACKEND_ALL to specify a single include file that contains 18 | the include directives for all of the platform's header files 19 | 20 | 3. Use GB_INCLUDE_BACKEND_MATRIX to specify the include file that defines the 21 | platform's Matrix base class 22 | 23 | 4. Use GB_INCLUDE_BACKEND_VECTOR to specify the include file that defines the 24 | platform's Vector base class 25 | 26 | 5. Use GB_INCLUDE_BACKEND_UTILITY to specify the include file that defines 27 | the pretty_print and pretty_print_matrix functions. 28 | 29 | 6. Use GB_INCLUDE_BACKEND_TRANSPOSE_VIEW to specify the include file that 30 | defines the platform's TransposeView class 31 | 32 | 7. Use GB_INCLUDE_BACKEND_COMPLEMENT_VIEW to specify the include file that defines the platform's ComplementView class 33 | 34 | 8. Use GB_INCLUDE_BACKEND_OPERATIONS to specify the include file(s) that 35 | defines the platform's operations functions. 36 | -------------------------------------------------------------------------------- /src/graphblas/platforms/backend_include_template.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | // !!!! DO NOT ADD HEADER INCLUSION PROTECTION !!!! 29 | 30 | // This file is a dispatch mechanism to allow us to include different 31 | // sets of files as specified by the user. 32 | 33 | // 1. Global search and replace GB_BACKEND_NAME with the name of the 34 | // platform directory. 35 | 36 | // 2. Specify a single include file that contains the include 37 | // directives for all of the platform's header files 38 | #if(GB_INCLUDE_BACKEND_ALL) 39 | #include 40 | #undef GB_INCLUDE_BACKEND_ALL 41 | #endif 42 | 43 | // 3. Specify the include file that defines the platform's Matrix base class 44 | #if(GB_INCLUDE_BACKEND_MATRIX) 45 | #include 46 | #undef GB_INCLUDE_BACKEND_MATRIX 47 | #endif 48 | 49 | // 4. Specify the include file that defines the platform's Vector base class 50 | #if(GB_INCLUDE_BACKEND_VECTOR) 51 | #include 52 | #undef GB_INCLUDE_BACKEND_VECTOR 53 | #endif 54 | 55 | // 5. Specify the include file(s) that defines the platform's 56 | // operations functions. 57 | #if(GB_INCLUDE_BACKEND_OPERATIONS) 58 | #include 59 | #undef GB_INCLUDE_BACKEND_OPERATIONS 60 | #endif 61 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/Matrix.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | 35 | namespace grb 36 | { 37 | namespace backend 38 | { 39 | //******************************************************************** 40 | template 41 | class Matrix : public LilSparseMatrix 42 | { 43 | private: 44 | using ParentMatrixType = LilSparseMatrix; 45 | 46 | public: 47 | using ScalarType = ScalarT; 48 | 49 | // construct an empty matrix of fixed dimensions 50 | Matrix(IndexType num_rows, 51 | IndexType num_cols) 52 | : ParentMatrixType(num_rows, num_cols) 53 | { 54 | } 55 | 56 | // copy construct 57 | Matrix(Matrix const &rhs) 58 | : ParentMatrixType(rhs) 59 | { 60 | } 61 | 62 | // construct a dense matrix from dense data. 63 | Matrix(std::vector > const &values) 64 | : ParentMatrixType(values) 65 | { 66 | } 67 | 68 | // construct a sparse matrix from dense data and a zero val. 69 | Matrix(std::vector > const &values, 70 | ScalarT zero) 71 | : ParentMatrixType(values, zero) 72 | { 73 | } 74 | 75 | ~Matrix() {} // virtual? 76 | 77 | // necessary? 78 | bool operator==(Matrix const &rhs) const 79 | { 80 | return ParentMatrixType::operator==(rhs); 81 | } 82 | 83 | // necessary? 84 | bool operator!=(Matrix const &rhs) const 85 | { 86 | return ParentMatrixType::operator!=(rhs); 87 | } 88 | 89 | void printInfo(std::ostream &os) const 90 | { 91 | os << "Optimized_Sequential Backend: "; 92 | ParentMatrixType::printInfo(os); 93 | } 94 | }; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/Vector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grb 38 | { 39 | namespace backend 40 | { 41 | //********************************************************************** 42 | /// @note ignoring all tags here, there is currently only one 43 | /// implementation of vector: dense+bitmap. 44 | template 45 | class Vector : public BitmapSparseVector 46 | { 47 | private: 48 | using ParentVectorType = BitmapSparseVector; 49 | 50 | public: 51 | using ScalarType = ScalarT; 52 | 53 | Vector() = delete; 54 | 55 | Vector(IndexType nsize) : ParentVectorType(nsize) {} 56 | 57 | Vector(IndexType const &nsize, ScalarT const &value) 58 | : ParentVectorType(nsize, value) {} 59 | 60 | Vector(std::vector const &values) 61 | : ParentVectorType(values) {} 62 | 63 | Vector(std::vector const &values, ScalarT const &zero) 64 | : ParentVectorType(values, zero) {} 65 | 66 | ~Vector() {} // virtual? 67 | 68 | // necessary? 69 | bool operator==(Vector const &rhs) const 70 | { 71 | return ParentVectorType::operator==(rhs); 72 | } 73 | 74 | // necessary? 75 | bool operator!=(Vector const &rhs) const 76 | { 77 | return ParentVectorType::operator!=(rhs); 78 | } 79 | 80 | void printInfo(std::ostream &os) const 81 | { 82 | os << "Optimized Sequential Backend: "; 83 | ParentVectorType::printInfo(os); 84 | } 85 | }; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/backend_include.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | // !!!! DO NOT ADD HEADER INCLUSION PROTECTION !!!! 29 | 30 | // This file is a dispatch mechanism to allow us to include different 31 | // sets of files as specified by the user. 32 | 33 | #if(GB_INCLUDE_BACKEND_ALL) 34 | #include 35 | #endif 36 | 37 | #if(GB_INCLUDE_BACKEND_MATRIX) 38 | #include 39 | #undef GB_INCLUDE_BACKEND_MATRIX 40 | #endif 41 | 42 | #if(GB_INCLUDE_BACKEND_VECTOR) 43 | #include 44 | #undef GB_INCLUDE_BACKEND_VECTOR 45 | #endif 46 | 47 | #if(GB_INCLUDE_BACKEND_OPERATIONS) 48 | #include 49 | #undef GB_INCLUDE_BACKEND_OPERATIONS 50 | #endif 51 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/operations.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | /** 29 | * Implementations of all GraphBLAS functions optimized for the sequential 30 | * (CPU) backend. 31 | */ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | // Add individual operation files here 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/optimized_sequential.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/sparse_transpose.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "sparse_helpers.hpp" 40 | #include "LilSparseMatrix.hpp" 41 | 42 | //****************************************************************************** 43 | 44 | namespace grb 45 | { 46 | namespace backend 47 | { 48 | //********************************************************************** 49 | // Implementation of 4.3.10 Matrix transpose 50 | template 54 | inline void transpose(CMatrixT &C, 55 | MaskT const &mask, 56 | AccumT const &accum, 57 | AMatrixT const &A, 58 | OutputControlEnum outp) 59 | { 60 | GRB_LOG_VERBOSE("C := A'"); 61 | IndexType nrows(A.nrows()); 62 | IndexType ncols(A.ncols()); 63 | 64 | // ================================================================= 65 | // Transpose A into T. 66 | LilSparseMatrix T(ncols, nrows); 67 | if (A.nvals() > 0) 68 | { 69 | for (IndexType row_idx = 0; row_idx < A.nrows(); ++row_idx) 70 | { 71 | for (auto && [col_idx, val] : A[row_idx]) 72 | { 73 | T[col_idx].emplace_back(row_idx, val); 74 | } 75 | } 76 | T.recomputeNvals(); 77 | } 78 | // ================================================================= 79 | // Accumulate T via C into Z 80 | using ZScalarType = typename std::conditional_t< 81 | std::is_same_v, 82 | typename AMatrixT::ScalarType, 83 | decltype(accum(std::declval(), 84 | std::declval()))>; 85 | 86 | LilSparseMatrix Z(ncols, nrows); 87 | ewise_or_opt_accum(Z, C, T, accum); 88 | 89 | // ================================================================= 90 | // Copy Z into the final output considering mask and replace/merge 91 | write_with_opt_mask(C, Z, mask, outp); 92 | } 93 | 94 | //********************************************************************** 95 | // Implementation of 4.3.10 Matrix transpose 96 | //********************************************************************** 97 | template 101 | inline void transpose(CMatrixT &C, 102 | MaskT const &mask, 103 | AccumT const &accum, 104 | TransposeView const &AT, 105 | OutputControlEnum outp) 106 | { 107 | GRB_LOG_VERBOSE("C := (A')'"); 108 | auto const &A(AT.m_mat); 109 | IndexType nrows(A.nrows()); 110 | IndexType ncols(A.ncols()); 111 | 112 | // ================================================================= 113 | /// Do nothing for T if A is TransposeView, Use A in next step. 114 | 115 | // ================================================================= 116 | // Accumulate A via C into Z 117 | using ZScalarType = typename std::conditional_t< 118 | std::is_same_v, 119 | typename AMatrixT::ScalarType, 120 | decltype(accum(std::declval(), 121 | std::declval()))>; 122 | 123 | LilSparseMatrix Z(nrows, ncols); 124 | ewise_or_opt_accum(Z, C, A, accum); 125 | 126 | // ================================================================= 127 | // Copy Z into the final output considering mask and replace/merge 128 | write_with_opt_mask(C, Z, mask, outp); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/graphblas/platforms/optimized_sequential/sparse_vxm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "sparse_helpers.hpp" 38 | 39 | //**************************************************************************** 40 | 41 | namespace grb 42 | { 43 | namespace backend 44 | { 45 | //******************************************************************** 46 | /// Implementation of 4.3.2 vxm: u * A 47 | //******************************************************************** 48 | template 54 | inline void vxm(WVectorT &w, 55 | MaskT const &mask, 56 | AccumT const &accum, 57 | SemiringT op, 58 | UVectorT const &u, 59 | AMatrixT const &A, 60 | OutputControlEnum outp) 61 | { 62 | GRB_LOG_VERBOSE("w := u +.* A"); 63 | 64 | // ================================================================= 65 | // Use axpy approach with the semi-ring. 66 | using TScalarType = typename SemiringT::result_type; 67 | std::vector > t; 68 | 69 | if ((A.nvals() > 0) && (u.nvals() > 0)) 70 | { 71 | for (IndexType row_idx = 0; row_idx < u.size(); ++row_idx) 72 | { 73 | if (u.hasElement(row_idx) && !A[row_idx].empty()) 74 | { 75 | axpy(t, op, u.extractElement(row_idx), A[row_idx]); 76 | } 77 | } 78 | } 79 | 80 | // ================================================================= 81 | // Accumulate into Z 82 | using ZScalarType = typename std::conditional_t< 83 | std::is_same_v, 84 | TScalarType, 85 | decltype(accum(std::declval(), 86 | std::declval()))>; 87 | 88 | std::vector > z; 89 | ewise_or_opt_accum_1D(z, w, t, accum); 90 | 91 | // ================================================================= 92 | // Copy Z into the final output, w, considering mask and replace/merge 93 | write_with_opt_mask_1D(w, z, mask, outp); 94 | } 95 | 96 | //********************************************************************** 97 | //********************************************************************** 98 | //********************************************************************** 99 | 100 | //******************************************************************** 101 | /// Implementation of 4.3.2 vxm: u * A' 102 | //******************************************************************** 103 | template 109 | inline void vxm(WVectorT &w, 110 | MaskT const &mask, 111 | AccumT const &accum, 112 | SemiringT op, 113 | UVectorT const &u, 114 | TransposeView const &AT, 115 | OutputControlEnum outp) 116 | { 117 | GRB_LOG_VERBOSE("w := u +.* A'"); 118 | auto const &A(AT.m_mat); 119 | 120 | // ================================================================= 121 | // Do the basic dot-product work with the semi-ring. 122 | using TScalarType = typename SemiringT::result_type; 123 | std::vector > t; 124 | 125 | if ((A.nvals() > 0) && (u.nvals() > 0)) 126 | { 127 | auto u_contents(u.getContents()); 128 | for (IndexType row_idx = 0; row_idx < w.size(); ++row_idx) 129 | { 130 | if (!A[row_idx].empty()) 131 | { 132 | TScalarType t_val; 133 | if (dot(t_val, u_contents, A[row_idx], op)) 134 | { 135 | t.emplace_back(row_idx, t_val); 136 | } 137 | } 138 | } 139 | } 140 | 141 | // ================================================================= 142 | // Accumulate into Z 143 | using ZScalarType = typename std::conditional_t< 144 | std::is_same_v, 145 | TScalarType, 146 | decltype(accum(std::declval(), 147 | std::declval()))>; 148 | 149 | std::vector > z; 150 | ewise_or_opt_accum_1D(z, w, t, accum); 151 | 152 | // ================================================================= 153 | // Copy Z into the final output, w, considering mask and replace/merge 154 | write_with_opt_mask_1D(w, z, mask, outp); 155 | } 156 | 157 | } // backend 158 | } // grb 159 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/Matrix.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | //**************************************************************************** 34 | 35 | namespace grb 36 | { 37 | namespace backend 38 | { 39 | //******************************************************************** 40 | template 41 | class Matrix : public LilSparseMatrix 42 | { 43 | private: 44 | using ParentMatrixType = LilSparseMatrix; 45 | 46 | public: 47 | using ScalarType = ScalarT; 48 | 49 | // construct an empty matrix of fixed dimensions 50 | Matrix(IndexType num_rows, 51 | IndexType num_cols) 52 | : ParentMatrixType(num_rows, num_cols) 53 | { 54 | } 55 | 56 | // copy construct 57 | Matrix(Matrix const &rhs) 58 | : ParentMatrixType(rhs) 59 | { 60 | } 61 | 62 | // construct a dense matrix from dense data. 63 | Matrix(std::vector > const &values) 64 | : ParentMatrixType(values) 65 | { 66 | } 67 | 68 | // construct a sparse matrix from dense data and a zero val. 69 | Matrix(std::vector > const &values, 70 | ScalarT zero) 71 | : ParentMatrixType(values, zero) 72 | { 73 | } 74 | 75 | ~Matrix() {} // virtual? 76 | 77 | // necessary? 78 | bool operator==(Matrix const &rhs) const 79 | { 80 | return ParentMatrixType::operator==(rhs); 81 | } 82 | 83 | // necessary? 84 | bool operator!=(Matrix const &rhs) const 85 | { 86 | return ParentMatrixType::operator!=(rhs); 87 | } 88 | 89 | void printInfo(std::ostream &os) const 90 | { 91 | os << "Sequential Backend: "; 92 | ParentMatrixType::printInfo(os); 93 | } 94 | }; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/Vector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grb 38 | { 39 | namespace backend 40 | { 41 | //********************************************************************** 42 | /// @note ignoring all tags here, there is currently only one 43 | /// implementation of vector: dense+bitmap. 44 | template 45 | class Vector : public BitmapSparseVector 46 | { 47 | private: 48 | using ParentVectorType = BitmapSparseVector; 49 | 50 | public: 51 | using ScalarType = ScalarT; 52 | 53 | Vector() = delete; 54 | 55 | Vector(IndexType nsize) : ParentVectorType(nsize) {} 56 | 57 | Vector(IndexType const &nsize, ScalarT const &value) 58 | : ParentVectorType(nsize, value) {} 59 | 60 | Vector(std::vector const &values) 61 | : ParentVectorType(values) {} 62 | 63 | Vector(std::vector const &values, ScalarT const &zero) 64 | : ParentVectorType(values, zero) {} 65 | 66 | ~Vector() {} // virtual? 67 | 68 | // necessary? 69 | bool operator==(Vector const &rhs) const 70 | { 71 | return ParentVectorType::operator==(rhs); 72 | } 73 | 74 | // necessary? 75 | bool operator!=(Vector const &rhs) const 76 | { 77 | return ParentVectorType::operator!=(rhs); 78 | } 79 | 80 | void printInfo(std::ostream &os) const 81 | { 82 | os << "Sequential Backend: "; 83 | ParentVectorType::printInfo(os); 84 | } 85 | }; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/backend_include.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | // !!!! DO NOT ADD HEADER INCLUSION PROTECTION !!!! 29 | 30 | // This file is a dispatch mechanism to allow us to include different 31 | // sets of files as specified by the user. 32 | 33 | #if(GB_INCLUDE_BACKEND_ALL) 34 | #include 35 | #endif 36 | 37 | #if(GB_INCLUDE_BACKEND_MATRIX) 38 | #include 39 | #undef GB_INCLUDE_BACKEND_MATRIX 40 | #endif 41 | 42 | #if(GB_INCLUDE_BACKEND_VECTOR) 43 | #include 44 | #undef GB_INCLUDE_BACKEND_VECTOR 45 | #endif 46 | 47 | #if(GB_INCLUDE_BACKEND_OPERATIONS) 48 | #include 49 | #undef GB_INCLUDE_BACKEND_OPERATIONS 50 | #endif 51 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/operations.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | /** 29 | * Implementations of all GraphBLAS functions optimized for the sequential 30 | * (CPU) backend. 31 | */ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | // Add individual operation files here 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/sequential.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/sparse_transpose.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "sparse_helpers.hpp" 40 | #include "LilSparseMatrix.hpp" 41 | 42 | //****************************************************************************** 43 | 44 | namespace grb 45 | { 46 | namespace backend 47 | { 48 | //********************************************************************** 49 | // Implementation of 4.3.10 Matrix transpose 50 | template 54 | inline void transpose(CMatrixT &C, 55 | MaskT const &mask, 56 | AccumT const &accum, 57 | AMatrixT const &A, 58 | OutputControlEnum outp) 59 | { 60 | GRB_LOG_VERBOSE("C := A'"); 61 | IndexType nrows(A.nrows()); 62 | IndexType ncols(A.ncols()); 63 | 64 | // ================================================================= 65 | // Transpose A into T. 66 | LilSparseMatrix T(ncols, nrows); 67 | if (A.nvals() > 0) 68 | { 69 | for (IndexType row_idx = 0; row_idx < A.nrows(); ++row_idx) 70 | { 71 | for (auto && [col_idx, val] : A[row_idx]) 72 | { 73 | T[col_idx].emplace_back(row_idx, val); 74 | } 75 | } 76 | T.recomputeNvals(); 77 | } 78 | // ================================================================= 79 | // Accumulate T via C into Z 80 | using ZScalarType = typename std::conditional_t< 81 | std::is_same_v, 82 | typename AMatrixT::ScalarType, 83 | decltype(accum(std::declval(), 84 | std::declval()))>; 85 | 86 | LilSparseMatrix Z(ncols, nrows); 87 | ewise_or_opt_accum(Z, C, T, accum); 88 | 89 | // ================================================================= 90 | // Copy Z into the final output considering mask and replace/merge 91 | write_with_opt_mask(C, Z, mask, outp); 92 | } 93 | 94 | //********************************************************************** 95 | // Implementation of 4.3.10 Matrix transpose 96 | //********************************************************************** 97 | template 101 | inline void transpose(CMatrixT &C, 102 | MaskT const &mask, 103 | AccumT const &accum, 104 | TransposeView const &AT, 105 | OutputControlEnum outp) 106 | { 107 | GRB_LOG_VERBOSE("C := (A')'"); 108 | auto const &A(AT.m_mat); 109 | IndexType nrows(A.nrows()); 110 | IndexType ncols(A.ncols()); 111 | 112 | // ================================================================= 113 | /// Do nothing for T if A is TransposeView, Use A in next step. 114 | 115 | // ================================================================= 116 | // Accumulate A via C into Z 117 | using ZScalarType = typename std::conditional_t< 118 | std::is_same_v, 119 | typename AMatrixT::ScalarType, 120 | decltype(accum(std::declval(), 121 | std::declval()))>; 122 | 123 | LilSparseMatrix Z(nrows, ncols); 124 | ewise_or_opt_accum(Z, C, A, accum); 125 | 126 | // ================================================================= 127 | // Copy Z into the final output considering mask and replace/merge 128 | write_with_opt_mask(C, Z, mask, outp); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/sparse_vxm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "sparse_helpers.hpp" 38 | 39 | //**************************************************************************** 40 | 41 | namespace grb 42 | { 43 | namespace backend 44 | { 45 | //******************************************************************** 46 | /// Implementation of 4.3.2 vxm: u * A 47 | //******************************************************************** 48 | template 54 | inline void vxm(WVectorT &w, 55 | MaskT const &mask, 56 | AccumT const &accum, 57 | SemiringT op, 58 | UVectorT const &u, 59 | AMatrixT const &A, 60 | OutputControlEnum outp) 61 | { 62 | GRB_LOG_VERBOSE("w := u +.* A"); 63 | 64 | // ================================================================= 65 | // Use axpy approach with the semi-ring. 66 | using TScalarType = typename SemiringT::result_type; 67 | std::vector > t; 68 | 69 | if ((A.nvals() > 0) && (u.nvals() > 0)) 70 | { 71 | for (IndexType row_idx = 0; row_idx < u.size(); ++row_idx) 72 | { 73 | if (u.hasElement(row_idx) && !A[row_idx].empty()) 74 | { 75 | axpy(t, op, u.extractElement(row_idx), A[row_idx]); 76 | } 77 | } 78 | } 79 | 80 | // ================================================================= 81 | // Accumulate into Z 82 | using ZScalarType = typename std::conditional_t< 83 | std::is_same_v, 84 | TScalarType, 85 | decltype(accum(std::declval(), 86 | std::declval()))>; 87 | 88 | std::vector > z; 89 | ewise_or_opt_accum_1D(z, w, t, accum); 90 | 91 | // ================================================================= 92 | // Copy Z into the final output, w, considering mask and replace/merge 93 | write_with_opt_mask_1D(w, z, mask, outp); 94 | } 95 | 96 | //********************************************************************** 97 | //********************************************************************** 98 | //********************************************************************** 99 | 100 | //******************************************************************** 101 | /// Implementation of 4.3.2 vxm: u * A' 102 | //******************************************************************** 103 | template 109 | inline void vxm(WVectorT &w, 110 | MaskT const &mask, 111 | AccumT const &accum, 112 | SemiringT op, 113 | UVectorT const &u, 114 | TransposeView const &AT, 115 | OutputControlEnum outp) 116 | { 117 | GRB_LOG_VERBOSE("w := u +.* A'"); 118 | auto const &A(AT.m_mat); 119 | 120 | // ================================================================= 121 | // Do the basic dot-product work with the semi-ring. 122 | using TScalarType = typename SemiringT::result_type; 123 | std::vector > t; 124 | 125 | if ((A.nvals() > 0) && (u.nvals() > 0)) 126 | { 127 | auto u_contents(u.getContents()); 128 | for (IndexType row_idx = 0; row_idx < w.size(); ++row_idx) 129 | { 130 | if (!A[row_idx].empty()) 131 | { 132 | TScalarType t_val; 133 | if (dot(t_val, u_contents, A[row_idx], op)) 134 | { 135 | t.emplace_back(row_idx, t_val); 136 | } 137 | } 138 | } 139 | } 140 | 141 | // ================================================================= 142 | // Accumulate into Z 143 | using ZScalarType = typename std::conditional_t< 144 | std::is_same_v, 145 | TScalarType, 146 | decltype(accum(std::declval(), 147 | std::declval()))>; 148 | 149 | std::vector > z; 150 | ewise_or_opt_accum_1D(z, w, t, accum); 151 | 152 | // ================================================================= 153 | // Copy Z into the final output, w, considering mask and replace/merge 154 | write_with_opt_mask_1D(w, z, mask, outp); 155 | } 156 | 157 | } // backend 158 | } // grb 159 | -------------------------------------------------------------------------------- /src/graphblas/platforms/sequential/test/run_tests.sh: -------------------------------------------------------------------------------- 1 | find . -name "test_*" -perm /u+x | while read test; do echo "Now running $test..." && ./$test && echo ""; done 2 | -------------------------------------------------------------------------------- /src/graphblas/types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * DM20-0442 26 | */ 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace grb 36 | { 37 | using IndexType = uint64_t; /// @todo Consider template param for index type 38 | using IndexArrayType = std::vector; 39 | 40 | //************************************************************************** 41 | // When an operation uses a mask this controls what happens to non-masked 42 | // elements in the resulting container: 43 | // MERGE -> leave as is, 44 | // REPLACE -> clear (annihilate) element. 45 | // 46 | /// @todo replace with a scoped enum; i.e., "enum class OutputControlEnum.." 47 | enum OutputControlEnum 48 | { 49 | MERGE = 0, 50 | REPLACE = 1 51 | }; 52 | 53 | //************************************************************************** 54 | struct NoAccumulate 55 | { 56 | // It doesn't really matter what the type is, it never gets executed. 57 | template 58 | inline D3 operator()(D1 lhs, D2 rhs) const { return true; } 59 | }; 60 | 61 | //************************************************************************** 62 | class NoMask 63 | { 64 | public: 65 | friend std::ostream &operator<<(std::ostream &os, 66 | NoMask const &mask) 67 | { 68 | os << "No mask"; 69 | return os; 70 | } 71 | 72 | friend inline NoMask const &get_internal_matrix(NoMask const &mask) 73 | { 74 | return mask; 75 | } 76 | 77 | friend inline NoMask const &get_internal_vector(NoMask const &mask) 78 | { 79 | return mask; 80 | } 81 | }; 82 | 83 | //************************************************************************** 84 | template class Vector; 85 | 86 | template 87 | inline constexpr bool is_vector_v = false; 88 | 89 | template 90 | inline constexpr bool is_vector_v> = true; 91 | 92 | //************************************************************************ 93 | template class Matrix; 94 | 95 | template 96 | inline constexpr bool is_matrix_v = false; 97 | 98 | template 99 | inline constexpr bool is_matrix_v> = true; 100 | 101 | //************************************************************************ 102 | template class VectorComplementView; 103 | template class VectorStructureView; 104 | template class VectorStructuralComplementView; 105 | 106 | template class TransposeView; 107 | template class MatrixComplementView; 108 | template class MatrixStructureView; 109 | template class MatrixStructuralComplementView; 110 | 111 | template 112 | inline constexpr bool is_matrix_v> = true; 113 | 114 | //************************************************************************ 115 | template 116 | inline constexpr bool is_complement_v = false; 117 | 118 | template 119 | inline constexpr bool is_complement_v> = true; 120 | 121 | template 122 | inline constexpr bool is_complement_v> = true; 123 | 124 | 125 | template 126 | inline constexpr bool is_structure_v = false; 127 | 128 | template 129 | inline constexpr bool is_structure_v> = true; 130 | 131 | template 132 | inline constexpr bool is_structure_v> = true; 133 | 134 | 135 | template 136 | inline constexpr bool is_structural_complement_v = false; 137 | 138 | template 139 | inline constexpr bool is_structural_complement_v< 140 | MatrixStructuralComplementView> = true; 141 | 142 | template 143 | inline constexpr bool is_structural_complement_v< 144 | VectorStructuralComplementView> = true; 145 | 146 | 147 | template 148 | inline constexpr bool is_transpose_v = false; 149 | 150 | template 151 | inline constexpr bool is_transpose_v> = true; 152 | } 153 | -------------------------------------------------------------------------------- /src/test/.gitignore: -------------------------------------------------------------------------------- 1 | *.gcno 2 | *.gcda 3 | *.gcov 4 | test_*_bfs 5 | test_*_apply 6 | test_*_assign 7 | test_*_column_extended_view 8 | test_*_constant_matrix 9 | test_*_ewiseapply 10 | test_*_extract 11 | test_*_extracttuples 12 | test_*_gemm 13 | test_*_reduce 14 | test_*_csc_matrix 15 | test_*_coo_matrix 16 | test_*_csr_matrix 17 | test_*_dia_matrix 18 | test_*_lil_matrix 19 | test_math 20 | test_*_row_extended_view 21 | test_*_sssp 22 | -------------------------------------------------------------------------------- /src/test/test_cluster_louvain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | using namespace grb; 41 | using namespace algorithms; 42 | 43 | #define BOOST_TEST_MAIN 44 | #define BOOST_TEST_MODULE cluster_test_suite 45 | 46 | #include 47 | 48 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 49 | 50 | //**************************************************************************** 51 | BOOST_AUTO_TEST_CASE(cluster_test_louvain) 52 | { 53 | std::cout << "============== Louvain ================" << std::endl; 54 | grb::IndexArrayType i_m1 = {0, 0, 0, 0, 55 | 1, 1, 1, 1, 56 | 2, 2, 2, 2, 57 | 3, 3, 3, 3, 58 | 4, 4, 4, 4, 59 | 5, 5, 5, 5, 5, 60 | 6, 6, 6, 61 | 7, 7, 7, 7}; 62 | grb::IndexArrayType j_m1 = {0, 2, 3, 6, 63 | 1, 2, 3, 7, 64 | 0, 2, 4, 6, 65 | 0, 1, 3, 5, 66 | 0, 2, 4, 6, 67 | 1, 3, 5, 6, 7, 68 | 0, 4, 6, 69 | 1, 3, 5, 7}; 70 | std::vector v_m1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 71 | 1, 1, 1, 1, 1, 1, 1, 1, 72 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 73 | Matrix m1(8, 8); 74 | m1.build(i_m1, j_m1, v_m1); 75 | 76 | auto ans = algorithms::louvain_cluster(m1); 77 | 78 | auto cluster_assignments = get_louvain_cluster_assignments(ans); 79 | grb::print_vector(std::cout, cluster_assignments, "CLUSTER ASSIGNMENTS"); 80 | 81 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 82 | cluster_assignments.extractElement(2)); 83 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 84 | cluster_assignments.extractElement(4)); 85 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 86 | cluster_assignments.extractElement(6)); 87 | 88 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 89 | cluster_assignments.extractElement(3)); 90 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 91 | cluster_assignments.extractElement(5)); 92 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 93 | cluster_assignments.extractElement(7)); 94 | 95 | BOOST_CHECK(cluster_assignments.extractElement(0) != 96 | cluster_assignments.extractElement(1)); 97 | } 98 | 99 | //**************************************************************************** 100 | BOOST_AUTO_TEST_CASE(cluster_test_louvain_masked) 101 | { 102 | std::cout << "============== Louvain ================" << std::endl; 103 | grb::IndexArrayType i_m1 = {0, 0, 0, 0, 104 | 1, 1, 1, 1, 105 | 2, 2, 2, 2, 106 | 3, 3, 3, 3, 107 | 4, 4, 4, 4, 108 | 5, 5, 5, 5, 5, 109 | 6, 6, 6, 110 | 7, 7, 7, 7}; 111 | grb::IndexArrayType j_m1 = {0, 2, 3, 6, 112 | 1, 2, 3, 7, 113 | 0, 2, 4, 6, 114 | 0, 1, 3, 5, 115 | 0, 2, 4, 6, 116 | 1, 3, 5, 6, 7, 117 | 0, 4, 6, 118 | 1, 3, 5, 7}; 119 | std::vector v_m1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 120 | 1, 1, 1, 1, 1, 1, 1, 1, 121 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 122 | Matrix m1(8, 8); 123 | m1.build(i_m1, j_m1, v_m1); 124 | 125 | auto ans = algorithms::louvain_cluster_masked(m1); 126 | 127 | auto cluster_assignments = get_louvain_cluster_assignments(ans); 128 | grb::print_vector(std::cout, cluster_assignments, "CLUSTER ASSIGNMENTS"); 129 | 130 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 131 | cluster_assignments.extractElement(2)); 132 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 133 | cluster_assignments.extractElement(4)); 134 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(0), 135 | cluster_assignments.extractElement(6)); 136 | 137 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 138 | cluster_assignments.extractElement(3)); 139 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 140 | cluster_assignments.extractElement(5)); 141 | BOOST_CHECK_EQUAL(cluster_assignments.extractElement(1), 142 | cluster_assignments.extractElement(7)); 143 | 144 | BOOST_CHECK(cluster_assignments.extractElement(0) != 145 | cluster_assignments.extractElement(1)); 146 | } 147 | 148 | BOOST_AUTO_TEST_SUITE_END() 149 | -------------------------------------------------------------------------------- /src/test/test_extracttuples.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | using namespace grb; 38 | 39 | #define BOOST_TEST_MAIN 40 | #define BOOST_TEST_MODULE extracttuples_test_suite 41 | 42 | #include 43 | 44 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 45 | 46 | //**************************************************************************** 47 | BOOST_AUTO_TEST_CASE(extracttuples_test_simple) 48 | { 49 | IndexArrayType rows = {0, 0, 0, 1, 1, 1, 2, 2}; 50 | IndexArrayType columns = {1, 2, 3, 0, 2, 3, 0, 1}; 51 | std::vector values = {1, 2, 3, 4, 6, 7, 8, 9}; 52 | Matrix m1(3, 4); 53 | m1.build(rows, columns, values); 54 | 55 | IndexType nnz = m1.nvals(); 56 | IndexArrayType r(nnz), c(nnz); 57 | std::vector v(nnz); 58 | 59 | m1.extractTuples(r, c, v); 60 | 61 | /// @todo the following check should be a utility function 62 | 63 | // Check the result, but it may be out of order. 64 | bool success = true; 65 | for (IndexType ix = 0; ix < values.size(); ++ix) 66 | { 67 | // Note: no semantics defined for extractTuples regarding the 68 | // order of returned values, so using an O(N^2) approach 69 | // without sorting: 70 | bool found = false; 71 | for (IndexType iy = 0; iy < v.size(); ++iy) 72 | { 73 | if ((r[iy] == rows[ix]) && (c[iy] == columns[ix])) 74 | { 75 | found = true; 76 | if (v[iy] != values[ix]) 77 | { 78 | success = false; 79 | } 80 | break; 81 | } 82 | } 83 | if (!found) 84 | { 85 | success = false; 86 | } 87 | } 88 | 89 | BOOST_CHECK_EQUAL(success, true); 90 | } 91 | 92 | BOOST_AUTO_TEST_SUITE_END() 93 | -------------------------------------------------------------------------------- /src/test/test_matrix_build.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | 39 | using namespace grb; 40 | 41 | #define BOOST_TEST_MAIN 42 | #define BOOST_TEST_MODULE matrix_build_test_suite 43 | 44 | #include 45 | 46 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 47 | 48 | //**************************************************************************** 49 | BOOST_AUTO_TEST_CASE(matrix_build_test) 50 | { 51 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2}; 52 | IndexArrayType j = {1, 2, 3, 0, 2, 3, 0, 1}; 53 | std::vector v = {1, 2, 3, 4, 6, 7, 8, 9}; 54 | 55 | std::vector > mat = {{0, 1, 2, 3}, 56 | {4, 0, 6, 7}, 57 | {8, 9, 0, 0}}; 58 | 59 | Matrix m1(3, 4); 60 | m1.build(i, j, v); 61 | 62 | //std::cerr << m1 << std::endl; 63 | IndexType nnz = m1.nvals(); 64 | BOOST_CHECK_EQUAL(nnz, i.size()); 65 | 66 | IndexArrayType ii(nnz), jj(nnz); 67 | std::vector val(nnz); 68 | m1.extractTuples(ii, jj, val); 69 | BOOST_CHECK_EQUAL(nnz, ii.size()); 70 | BOOST_CHECK_EQUAL(nnz, jj.size()); 71 | BOOST_CHECK_EQUAL(nnz, val.size()); 72 | 73 | for (IndexType idx = 0; idx < val.size(); ++idx) 74 | { 75 | BOOST_CHECK_EQUAL(val[idx], mat[ii[idx]][jj[idx]]); 76 | } 77 | } 78 | 79 | //**************************************************************************** 80 | BOOST_AUTO_TEST_CASE(matrix_build_test_iterators) 81 | { 82 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2}; 83 | IndexArrayType j = {1, 2, 3, 0, 2, 3, 0, 1}; 84 | std::vector v = {1, 2, 3, 4, 6, 7, 8, 9}; 85 | 86 | std::vector > mat = {{0, 1, 2, 3}, 87 | {4, 0, 6, 7}, 88 | {8, 9, 0, 0}}; 89 | 90 | Matrix m1(3, 4); 91 | m1.build(i.begin(), j.begin(), v.begin(), i.size()); 92 | 93 | //std::cerr << m1 << std::endl; 94 | IndexType nnz = m1.nvals(); 95 | BOOST_CHECK_EQUAL(nnz, i.size()); 96 | 97 | IndexArrayType ii(nnz), jj(nnz); 98 | std::vector val(nnz); 99 | m1.extractTuples(ii, jj, val); 100 | BOOST_CHECK_EQUAL(nnz, ii.size()); 101 | BOOST_CHECK_EQUAL(nnz, jj.size()); 102 | BOOST_CHECK_EQUAL(nnz, val.size()); 103 | 104 | for (IndexType idx = 0; idx < val.size(); ++idx) 105 | { 106 | BOOST_CHECK_EQUAL(val[idx], mat[ii[idx]][jj[idx]]); 107 | } 108 | } 109 | 110 | BOOST_AUTO_TEST_SUITE_END() 111 | -------------------------------------------------------------------------------- /src/test/test_matrix_methods.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | 39 | using namespace grb; 40 | 41 | #define BOOST_TEST_MAIN 42 | #define BOOST_TEST_MODULE matrix_methods_test_suite 43 | 44 | #include 45 | 46 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 47 | 48 | //**************************************************************************** 49 | BOOST_AUTO_TEST_CASE(matrix_resize_test) 50 | { 51 | IndexArrayType i = {1, 2, 3, 4}; 52 | std::vector v = {1, 2, 3, 4}; 53 | 54 | // matrix = diag{ -, 1, 2, 3, 4, -}; 55 | 56 | IndexType const NSIZE = 6; 57 | Matrix m1(NSIZE, NSIZE); 58 | m1.build(i, i, v); 59 | //print_matrix(std::cerr, m1, "m1(6,6)"); 60 | 61 | BOOST_CHECK_EQUAL(m1.nvals(), i.size()); 62 | BOOST_CHECK_EQUAL(m1.nrows(), NSIZE); 63 | BOOST_CHECK_EQUAL(m1.ncols(), NSIZE); 64 | 65 | // Make it bigger and set an element 66 | m1.resize(2*NSIZE, 2*NSIZE); 67 | //print_matrix(std::cerr, m1, "m1(12,12)"); 68 | BOOST_CHECK_EQUAL(m1.nvals(), i.size()); 69 | BOOST_CHECK_EQUAL(m1.nrows(), 2*NSIZE); 70 | BOOST_CHECK_EQUAL(m1.ncols(), 2*NSIZE); 71 | 72 | m1.setElement(NSIZE + 1, NSIZE + 1, 99); 73 | 74 | BOOST_CHECK_EQUAL(m1.nvals(), i.size() + 1); 75 | BOOST_CHECK_EQUAL(m1.extractElement(NSIZE + 1, NSIZE + 1), 99); 76 | 77 | // Reduce num columns check remaining elements 78 | m1.resize(2*NSIZE, 4UL); 79 | //print_matrix(std::cerr, m1, "m1(12, 4)"); 80 | BOOST_CHECK_EQUAL(m1.nvals(), 3); 81 | BOOST_CHECK_EQUAL(m1.nrows(), 2*NSIZE); 82 | BOOST_CHECK_EQUAL(m1.ncols(), 4); 83 | BOOST_CHECK_EQUAL(m1.extractElement(1, 1), 1); 84 | BOOST_CHECK_EQUAL(m1.extractElement(2, 2), 2); 85 | BOOST_CHECK_EQUAL(m1.extractElement(3, 3), 3); 86 | 87 | // Reduce num rows check remaining elements 88 | m1.resize(3UL, 4UL); 89 | //print_matrix(std::cerr, m1, "m1(3, 4)"); 90 | BOOST_CHECK_EQUAL(m1.nvals(), 2); 91 | BOOST_CHECK_EQUAL(m1.nrows(), 3); 92 | BOOST_CHECK_EQUAL(m1.ncols(), 4); 93 | BOOST_CHECK_EQUAL(m1.extractElement(1, 1), 1); 94 | BOOST_CHECK_EQUAL(m1.extractElement(2, 2), 2); 95 | 96 | // reduce both and check remaining elements 97 | m1.resize(2UL, 2UL); 98 | //print_matrix(std::cerr, m1, "m1(2,2)"); 99 | BOOST_CHECK_EQUAL(m1.nvals(), 1); 100 | BOOST_CHECK_EQUAL(m1.nrows(), 2); 101 | BOOST_CHECK_EQUAL(m1.ncols(), 2); 102 | BOOST_CHECK_EQUAL(m1.extractElement(1, 1), 1); 103 | 104 | // Make it bigger show that elements don't reappear 105 | m1.resize(2*NSIZE, 2*NSIZE); 106 | //print_matrix(std::cerr, m1, "m1(12,12)"); 107 | BOOST_CHECK_EQUAL(m1.nvals(), 1); 108 | BOOST_CHECK_EQUAL(m1.nrows(), 2*NSIZE); 109 | BOOST_CHECK_EQUAL(m1.ncols(), 2*NSIZE); 110 | } 111 | 112 | //**************************************************************************** 113 | BOOST_AUTO_TEST_CASE(matrix_removeElement_test) 114 | { 115 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2}; 116 | IndexArrayType j = {1, 2, 3, 0, 2, 3, 0, 1}; 117 | std::vector v = {1, 2, 3, 4, 6, 7, 8, 9}; 118 | 119 | //std::vector > mat = {{0, 1, 2, 3}, 120 | // {4, 0, 6, 7}, 121 | // {8, 9, 0, 0}}; 122 | 123 | Matrix m1(3, 4); 124 | m1.build(i, j, v); 125 | 126 | BOOST_CHECK_EQUAL(m1.nvals(), i.size()); 127 | 128 | // remove something that does not exist 129 | BOOST_CHECK(!m1.hasElement(1, 1)); 130 | m1.removeElement(1, 1); 131 | BOOST_CHECK_EQUAL(m1.nvals(), i.size()); 132 | BOOST_CHECK(!m1.hasElement(1, 1)); 133 | 134 | // remove something that exists 135 | BOOST_CHECK(m1.hasElement(1, 2)); 136 | m1.removeElement(1, 2); 137 | BOOST_CHECK_EQUAL(m1.nvals(), i.size() - 1); 138 | BOOST_CHECK(!m1.hasElement(1, 2)); 139 | } 140 | 141 | BOOST_AUTO_TEST_SUITE_END() 142 | -------------------------------------------------------------------------------- /src/test/test_maxflow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | using namespace grb; 41 | 42 | #define BOOST_TEST_MAIN 43 | #define BOOST_TEST_MODULE maxflow_test_suite 44 | 45 | #include 46 | 47 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 48 | 49 | //**************************************************************************** 50 | BOOST_AUTO_TEST_CASE(maxflow_push_relabel_test) 51 | { 52 | IndexArrayType i = {0, 0, 1, 2, 2, 3, 4, 4}; 53 | IndexArrayType j = {1, 3, 2, 3, 5, 4, 1, 5}; 54 | std::vector v = {15, 4, 12, 3, 7, 10, 5, 10}; 55 | Matrix m1(6, 6); 56 | m1.build(i, j, v); 57 | 58 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 59 | auto result = algorithms::maxflow_push_relabel(m1, 0, 5); 60 | BOOST_CHECK_EQUAL(result, 14); 61 | } 62 | 63 | //**************************************************************************** 64 | BOOST_AUTO_TEST_CASE(maxflow_push_relabel_test2) 65 | { 66 | // s 1 2 3 4 5 6 t 67 | // m1({{-, 10, 5,15, -, -, -, -}, // s = 0 68 | // {-, -, 4, -, 9,15, -, -}, // 1 69 | // {-, -, -, 4, -, 8, -, -}, // 2 70 | // {-, -, -, -, -, -,30, -}, // 3 71 | // {-, -, -, -, -,15, -,10}, // 4 72 | // {-, -, -, -, -, -,15,10}, // 5 73 | // {-, -, 6, -, -, -, -,10}, // 6 74 | // {-, -, -, -, -, -, -, -}}); // t = 7 75 | 76 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6}; 77 | IndexArrayType j = {1, 2, 3, 2, 4, 5, 3, 5, 6, 5, 7, 6, 7, 2, 7}; 78 | std::vector v = {10,5,15, 4, 9,15, 4, 8,30,15,10,15,10, 6,10}; 79 | Matrix m1(8, 8); 80 | m1.build(i, j, v); 81 | 82 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 83 | auto result = algorithms::maxflow_push_relabel(m1, 0, 7); 84 | BOOST_CHECK_EQUAL(result, 28); 85 | } 86 | 87 | //**************************************************************************** 88 | BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test) 89 | { 90 | IndexArrayType i = {0, 0, 1, 2, 2, 3, 4, 4}; 91 | IndexArrayType j = {1, 3, 2, 3, 5, 4, 1, 5}; 92 | std::vector v = {15, 4, 12, 3, 7, 10, 5, 10}; 93 | Matrix m1(6, 6); 94 | m1.build(i, j, v); 95 | 96 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 97 | auto result = algorithms::maxflow_ford_fulk(m1, 0, 5); 98 | BOOST_CHECK_EQUAL(result, 14); 99 | } 100 | 101 | //**************************************************************************** 102 | BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test_counter_example) 103 | { 104 | /* 2 2 105 | * 1--6--3 106 | * 2 / / \ 10 107 | * / / \ 108 | * 0 / 5 109 | * \ / 9 / 110 | * 9 \ / / 2 111 | * 2-----4 112 | * 7 113 | */ 114 | IndexArrayType i = {0, 0, 1, 2, 2, 3, 4, 6}; 115 | IndexArrayType j = {1, 2, 6, 3, 4, 5, 5, 3}; 116 | std::vector v = {2, 9, 2, 9, 7,10, 2, 2}; 117 | Matrix m1(7, 7); 118 | m1.build(i, j, v); 119 | 120 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 121 | auto result = algorithms::maxflow_ford_fulk(m1, 0, 5); 122 | BOOST_CHECK_EQUAL(result, 11); 123 | } 124 | 125 | //**************************************************************************** 126 | BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test2) 127 | { 128 | // s 1 2 3 4 5 6 t 129 | // m1({{-, 10, 5,15, -, -, -, -}, // s = 0 130 | // {-, -, 4, -, 9,15, -, -}, // 1 131 | // {-, 4, -, 4, -, 8, -, -}, // 2 132 | // {-, -, -, -, -, -,30, -}, // 3 133 | // {-, -, -, -, -,15, -,10}, // 4 134 | // {-, -, -, -, -, -,15,10}, // 5 135 | // {-, -, 6, -, -, -, -,10}, // 6 136 | // {-, -, -, -, -, -, -, -}}); // t = 7 137 | 138 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6}; 139 | IndexArrayType j = {1, 2, 3, 2, 4, 5, 3, 5, 6, 5, 7, 6, 7, 2, 7}; 140 | std::vector v = {10,5,15, 4, 9,15, 4, 8,30,15,10,15,10, 6,10}; 141 | Matrix m1(8, 8); 142 | m1.build(i, j, v); 143 | 144 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 145 | auto result = algorithms::maxflow_ford_fulk(m1, 0, 7); 146 | BOOST_CHECK_EQUAL(result, 28); 147 | } 148 | 149 | //**************************************************************************** 150 | BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test2_bidirectional) 151 | { 152 | // s 1 2 3 4 5 6 t 153 | // m1({{-, 10, 5,15, -, -, -, -}, // s = 0 154 | // {-, -, 4, -, 9,15, -, -}, // 1 155 | // {-, 4, -, 4, -, 8, -, -}, // 2 156 | // {-, -, -, -, -, -,30, -}, // 3 157 | // {-, -, -, -, -,15, -,10}, // 4 158 | // {-, -, -, -, 5, -,15,10}, // 5 159 | // {-, -, 6, -, -, -, -,10}, // 6 160 | // {-, -, -, -, -, -, -, -}}); // t = 7 161 | 162 | IndexArrayType i = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 6}; 163 | IndexArrayType j = {1, 2, 3, 2, 4, 5, 1, 3, 5, 6, 5, 7, 4, 6, 7, 2, 7}; 164 | std::vector v = {10,5,15, 4, 9,15, 4, 4, 8,30,15,10, 5,15,10, 6,10}; 165 | Matrix m1(8, 8); 166 | m1.build(i, j, v); 167 | 168 | //grb::print_matrix(std::cerr, m1, "\nGraph"); 169 | auto result = algorithms::maxflow_ford_fulk(m1, 0, 7); 170 | BOOST_CHECK_EQUAL(result, 30); 171 | } 172 | 173 | BOOST_AUTO_TEST_SUITE_END() 174 | -------------------------------------------------------------------------------- /src/test/test_mst.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | using namespace grb; 41 | using namespace algorithms; 42 | 43 | #define BOOST_TEST_MAIN 44 | #define BOOST_TEST_MODULE mst_test_suite 45 | 46 | #include 47 | 48 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 49 | 50 | //**************************************************************************** 51 | BOOST_AUTO_TEST_CASE(mst_test_with_weight_one) 52 | { 53 | IndexType const NUM_NODES = 6; 54 | IndexArrayType i_m1 = {0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 55 | 4, 4, 4, 4, 4, 5, 5}; 56 | IndexArrayType j_m1 = {1, 3, 4, 0, 3, 4, 4, 5, 0, 1, 4, 57 | 0, 1, 2, 3, 5, 2, 4}; 58 | std::vector v_m1(i_m1.size(), 1); 59 | Matrix m1(NUM_NODES, NUM_NODES); 60 | m1.build(i_m1, j_m1, v_m1); 61 | grb::print_matrix(std::cout, m1, "GRAPH***"); 62 | 63 | std::vector ans = {99, 0, 4, 1, 3, 2}; 64 | grb::Vector answer(ans, 99); 65 | 66 | grb::Vector parents(NUM_NODES); 67 | auto result = mst(m1, parents); 68 | 69 | BOOST_CHECK_EQUAL(result, NUM_NODES - 1.0); 70 | BOOST_CHECK_EQUAL(parents, answer); 71 | 72 | std::cout << "MST weight = " << result << std::endl; 73 | grb::print_vector(std::cout, parents, "MST parent list"); 74 | } 75 | 76 | //**************************************************************************** 77 | BOOST_AUTO_TEST_CASE(mst_test_with_weight_various) 78 | { 79 | IndexType const NUM_NODES = 6; 80 | IndexArrayType i_m1 = {0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 81 | 4, 4, 4, 4, 4, 5, 5}; 82 | IndexArrayType j_m1 = {1, 3, 4, 0, 3, 4, 4, 5, 0, 1, 4, 83 | 0, 1, 2, 3, 5, 2, 4}; 84 | std::vector v_m1 = {2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 1, 85 | 1, 1, 1, 1, 1, 2, 1}; 86 | Matrix m1(NUM_NODES, NUM_NODES); 87 | m1.build(i_m1, j_m1, v_m1); 88 | grb::print_matrix(std::cout, m1, "GRAPH***"); 89 | 90 | std::vector ans = {99, 4, 4, 4, 0, 4}; 91 | grb::Vector answer(ans, 99); 92 | 93 | grb::Vector parents(NUM_NODES); 94 | auto result = mst(m1, parents); 95 | 96 | BOOST_CHECK_EQUAL(result, NUM_NODES - 1.0); 97 | BOOST_CHECK_EQUAL(parents, answer); 98 | 99 | std::cout << "MST weight = " << result << std::endl; 100 | grb::print_vector(std::cout, parents, "MST parent list"); 101 | } 102 | 103 | //**************************************************************************** 104 | BOOST_AUTO_TEST_CASE(mst_test_with_weights) 105 | { 106 | // m1({{0, 4, 0, 0, 0, 0, 0, 8, 0}, 107 | // {4, 0, 8, 0, 0, 0, 0,11, 0}, 108 | // {0, 8, 0, 7, 0, 4, 0, 0, 2}, 109 | // {0, 0, 7, 0, 9,14, 0, 0, 0}, 110 | // {0, 0, 0, 9, 0,10, 0, 0, 0}, 111 | // {0, 0, 4,14,10, 0, 2, 0, 0}, 112 | // {0, 0, 0, 0, 0, 2, 0, 1, 6}, 113 | // {8,11, 0, 0, 0, 0, 1, 0, 7}, 114 | // {0, 0, 2, 0, 0, 0, 6, 7, 0}}); 115 | IndexType const NUM_NODES = 9; 116 | IndexArrayType i_m1 = {0, 0, 1, 1, 1, 2, 2, 2, 2, 117 | 3, 3, 3, 4, 4, 5, 5, 5, 5, 118 | 6, 6, 6, 7, 7, 7, 7, 8, 8, 8}; 119 | IndexArrayType j_m1 = {1, 7, 0, 2, 7, 1, 3, 5, 8, 120 | 2, 4, 5, 3, 5, 2, 3, 4, 6, 121 | 5, 7, 8, 0, 1, 6, 8, 2, 6, 7}; 122 | std::vector v_m1 = {4, 8, 4, 8,11, 8, 7, 4, 2, 123 | 7, 9,14, 9,10, 4,14,10, 2, 124 | 2, 1, 6, 8,11, 1, 7, 2, 6, 7}; 125 | Matrix m1(NUM_NODES, NUM_NODES); 126 | m1.build(i_m1, j_m1, v_m1); 127 | grb::print_matrix(std::cout, m1, "GRAPH***"); 128 | 129 | std::vector ans = {99, 0, 1, 2, 3, 2, 5, 6, 2}; 130 | grb::Vector answer(ans, 99); 131 | 132 | grb::Vector parents(NUM_NODES); 133 | auto result = mst(m1, parents); 134 | 135 | BOOST_CHECK_EQUAL(result, 37); 136 | BOOST_CHECK_EQUAL(parents, answer); 137 | 138 | //BOOST_CHECK_EQUAL(result, correct_weight); 139 | std::cout << "MST weight = " << result << std::endl; 140 | grb::print_vector(std::cout, parents, "MST parent list"); 141 | } 142 | 143 | BOOST_AUTO_TEST_SUITE_END() 144 | -------------------------------------------------------------------------------- /src/test/test_vector_methods.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | 37 | #include 38 | 39 | using namespace grb; 40 | 41 | #define BOOST_TEST_MAIN 42 | #define BOOST_TEST_MODULE vector_methods_test_suite 43 | 44 | #include 45 | 46 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 47 | 48 | //**************************************************************************** 49 | BOOST_AUTO_TEST_CASE(vector_resize_test) 50 | { 51 | IndexArrayType i = {1, 2, 3}; 52 | std::vector v = {1, 2, 3}; 53 | 54 | //std::vector vec = { -, 1, 2, 3, -, -}; 55 | 56 | IndexType const NSIZE = 6; 57 | Vector v1(NSIZE); 58 | v1.build(i, v); 59 | 60 | BOOST_CHECK_EQUAL(v1.nvals(), i.size()); 61 | BOOST_CHECK_EQUAL(v1.size(), NSIZE); 62 | 63 | // Make it bigger and set an element 64 | v1.resize(2*NSIZE); 65 | BOOST_CHECK_EQUAL(v1.nvals(), i.size()); 66 | BOOST_CHECK_EQUAL(v1.size(), 2*NSIZE); 67 | 68 | v1.setElement(NSIZE + 1, 99); 69 | 70 | BOOST_CHECK_EQUAL(v1.extractElement(NSIZE + 1), 99); 71 | 72 | // Make it smaller and check remaining elements 73 | v1.resize(3UL); 74 | BOOST_CHECK_EQUAL(v1.size(), 3); 75 | BOOST_CHECK_EQUAL(v1.nvals(), 2); 76 | BOOST_CHECK_EQUAL(v1.extractElement(1), 1); 77 | BOOST_CHECK_EQUAL(v1.extractElement(2), 2); 78 | 79 | // Make it bigger show that elements don't reappear 80 | v1.resize(2*NSIZE); 81 | BOOST_CHECK_EQUAL(v1.nvals(), 2); 82 | BOOST_CHECK_EQUAL(v1.size(), 2*NSIZE); 83 | } 84 | 85 | //**************************************************************************** 86 | BOOST_AUTO_TEST_CASE(vector_removeElement_test) 87 | { 88 | IndexArrayType i = {1, 2, 3}; 89 | std::vector v = {1, 2, 3}; 90 | 91 | //std::vector vec = { -, 1, 2, 3, -, -}; 92 | 93 | Vector v1(6); 94 | v1.build(i, v); 95 | 96 | BOOST_CHECK_EQUAL(v1.nvals(), i.size()); 97 | 98 | // remove something that does not exist 99 | BOOST_CHECK(!v1.hasElement(4)); 100 | v1.removeElement(4); 101 | BOOST_CHECK_EQUAL(v1.nvals(), i.size()); 102 | BOOST_CHECK(!v1.hasElement(4)); 103 | 104 | // remove something that exists 105 | BOOST_CHECK(v1.hasElement(1)); 106 | v1.removeElement(1); 107 | BOOST_CHECK_EQUAL(v1.nvals(), i.size() - 1); 108 | BOOST_CHECK(!v1.hasElement(1)); 109 | } 110 | 111 | BOOST_AUTO_TEST_SUITE_END() 112 | -------------------------------------------------------------------------------- /src/test/test_version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GraphBLAS Template Library (GBTL), Version 3.0 3 | * 4 | * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and 5 | * Authors. 6 | * 7 | * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 8 | * THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR THE 9 | * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF 10 | * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR 11 | * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE 12 | * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 13 | * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 14 | * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS 15 | * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED 16 | * RIGHTS. 17 | * 18 | * Released under a BSD-style license, please see LICENSE file or contact 19 | * permission@sei.cmu.edu for full terms. 20 | * 21 | * [DISTRIBUTION STATEMENT A] This material has been approved for public release 22 | * and unlimited distribution. Please see Copyright notice for non-US 23 | * Government use and distribution. 24 | * 25 | * This Software includes and/or makes use of the following Third-Party Software 26 | * subject to its own license: 27 | * 28 | * 1. Boost Unit Test Framework 29 | * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html) 30 | * Copyright 2001 Boost software license, Gennadiy Rozental. 31 | * 32 | * DM20-0442 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | using namespace grb; 39 | 40 | #define BOOST_TEST_MAIN 41 | #define BOOST_TEST_MODULE get_version_test_suite 42 | 43 | #include 44 | 45 | BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) 46 | 47 | //**************************************************************************** 48 | BOOST_AUTO_TEST_CASE(test_get_version) 49 | { 50 | auto [version, subversion] = grb::getVersion(); 51 | 52 | BOOST_CHECK_EQUAL(version, 1U); 53 | BOOST_CHECK_EQUAL(subversion, 3U); 54 | } 55 | 56 | BOOST_AUTO_TEST_SUITE_END() 57 | --------------------------------------------------------------------------------