From 56142ffaf63d831ee564c0f8e9945533409ec861 Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Tue, 2 Jun 2020 14:55:16 -0500 Subject: [PATCH] extractElement tests --- Test/extract/CMakeLists.txt | 214 ++++++++++++++++++++++++++++++ Test/extract/Makefile | 38 ++++++ Test/extract/build/.gitignore | 4 + Test/extract/extract_test.c | 116 ++++++++++++++++ Test/extract/output_330draft1.txt | 62 +++++++++ Test/extract/output_330draft4.txt | 62 +++++++++ 6 files changed, 496 insertions(+) create mode 100644 Test/extract/CMakeLists.txt create mode 100644 Test/extract/Makefile create mode 100644 Test/extract/build/.gitignore create mode 100644 Test/extract/extract_test.c create mode 100644 Test/extract/output_330draft1.txt create mode 100644 Test/extract/output_330draft4.txt diff --git a/Test/extract/CMakeLists.txt b/Test/extract/CMakeLists.txt new file mode 100644 index 0000000000..3ccec84a0b --- /dev/null +++ b/Test/extract/CMakeLists.txt @@ -0,0 +1,214 @@ +#------------------------------------------------------------------------------- +# LAGraph/Test/extract/CMakeLists.txt: cmake script for LAGraph test +#------------------------------------------------------------------------------- + +# LAGraph, (... list all authors here) (c) 2019, All Rights Reserved. +# http://lagraph.org See LAGraph/LICENSE for license. + +# CMakeLists.txt: instructions for cmake to build LAGraph. +# An ANSI C11 compiler is required. +# +# First, install any GraphBLAS library. +# Alternatively, use ../GraphBLAS (see comments below). +# +# To compile and install the LAGraph library: +# +# make +# sudo make install +# +# Then to compile and run the Demos: +# +# cd Demos +# make +# +# If that fails for any reason, make sure your compiler supports ANSI C11. You +# could try changing your compiler, for example: +# +# cd build +# CC=icc cmake .. +# cd .. +# make +# +# Or, with other compilers: +# +# CC=xlc cmake .. +# CC=gcc cmake .. +# +# To remove all compiled files and libraries (except installed ones): +# +# make distclean + +#------------------------------------------------------------------------------- +# get the version +#------------------------------------------------------------------------------- + +# cmake 3.0 is preferred. +cmake_minimum_required ( VERSION 2.8.12 ) + +if ( CMAKE_VERSION VERSION_GREATER "3.0" ) + cmake_policy ( SET CMP0042 NEW ) + cmake_policy ( SET CMP0048 NEW ) +endif ( ) + +project ( extract_test ) + +#------------------------------------------------------------------------------- +# determine build type +#------------------------------------------------------------------------------- + +include ( GNUInstallDirs ) + +# For development only, not for end-users: +# set ( CMAKE_BUILD_TYPE Debug ) + +if ( NOT CMAKE_BUILD_TYPE ) + set ( CMAKE_BUILD_TYPE Release ) +endif ( ) + +#------------------------------------------------------------------------------- +# edit these lines to select your GraphBLAS library +#------------------------------------------------------------------------------- + +# link_directories ( /usr/local/lib ) +link_directories ( ../../../GraphBLAS/build ) +link_directories ( ../../build ) + +# include_directories ( /usr/local/include ) +include_directories ( ../../../GraphBLAS/Include ) +include_directories ( ../../Include ) + +#------------------------------------------------------------------------------- +# determine what user threading model to use +#------------------------------------------------------------------------------- + +include ( FindOpenMP ) +include ( FindThreads ) + +#------------------------------------------------------------------------------- +# report status +#------------------------------------------------------------------------------- + +message ( STATUS "CMAKE build type: " ${CMAKE_BUILD_TYPE} ) + +if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug") + message ( STATUS "CMAKE C Flags debug: " ${CMAKE_C_FLAGS_DEBUG} ) +else ( ) + message ( STATUS "CMAKE C Flags release: " ${CMAKE_C_FLAGS_RELEASE} ) +endif ( ) + +message ( STATUS "CMAKE compiler ID: " ${CMAKE_C_COMPILER_ID} ) +message ( STATUS "CMAKE thread library: " ${CMAKE_THREAD_LIBS_INIT} ) +message ( STATUS "CMAKE have pthreads: " ${CMAKE_USE_PTHREADS_INIT} ) +message ( STATUS "CMAKE have Win32 pthreads: " ${CMAKE_USE_WIN32_THREADS_INIT} ) +message ( STATUS "CMAKE have OpenMP: " ${OPENMP_FOUND} ) + +#------------------------------------------------------------------------------- +# include directories +#------------------------------------------------------------------------------- + +set ( CMAKE_INCLUDE_CURRENT_DIR ON ) + +#------------------------------------------------------------------------------- +# compiler options +#------------------------------------------------------------------------------- + +# check which compiler is being used. If you need to make +# compiler-specific modifications, here is the place to do it. +if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + # cmake 2.8 workaround: gcc needs to be told to do ANSI C11. + # cmake 3.0 doesn't have this problem. + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -lm -Wno-pragmas " ) + # check all warnings: +# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror " ) + if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9 ) + message ( FATAL_ERROR "gcc version must be at least 4.9" ) + endif ( ) +elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" ) + # options for icc: also needs -std=c11 + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 " ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qopt-malloc-options=3" ) + # check all warnings: +# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w3 " ) + if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0 ) + message ( FATAL_ERROR "icc version must be at least 18.0" ) + endif ( ) +elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" ) + # options for clang + if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 3.3 ) + message ( FATAL_ERROR "clang version must be at least 3.3" ) + endif ( ) +elseif ( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" ) + # options for MicroSoft Visual Studio +endif ( ) + +if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}" ) +else ( ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}" ) +endif ( ) + +#------------------------------------------------------------------------------- +# select the threading library +#------------------------------------------------------------------------------- + +if ( USER_OPENMP ) + # user insists on OpenMP synchronization inside LAGraph + message ( STATUS "cmake -DUSER_OPENMP=1: insisting on using OpenMP" ) + set ( USE_OPENMP true ) +elseif ( USER_POSIX ) + # user insists on POSIX synchronization inside LAGraph + message ( STATUS "cmake -DUSER_POSIX=1: insisting on using POSIX" ) + set ( USE_POSIX true ) +elseif ( USER_NONE ) + message ( STATUS "cmake -DUSER_NONE=1: insisting on using no threading" ) + set ( USE_NONE true ) +else ( ) + # default: automatic selection + message ( STATUS "Automatic selection of synchronization method" ) + if ( OPENMP_FOUND ) + set ( USE_OPENMP true ) + elseif ( CMAKE_USE_PTHREADS_INIT ) + set ( USE_POSIX true ) + endif ( ) +endif ( ) + +# add the threading library +if ( USE_OPENMP ) + # use OpenMP + message ( STATUS "Using OpenMP to synchronize user threads" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -DUSER_OPENMP_THREADS " ) +elseif ( USE_POSIX ) + # use POSIX + message ( STATUS "Using POSIX pthreads to synchronize user threads" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -DUSER_POSIX_THREADS " ) +else ( ) + # use no threading at all + message ( WARNING "No support for user threads; LAGraph will not be thread-safe" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSER_NO_THREADS " ) +endif ( ) + +if ( CMAKE_USE_PTHREADS_INIT ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_PTHREADS " ) +endif ( ) + +if ( CMAKE_USE_WIN32_THREADS_INIT ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_WINDOWS_THREADS " ) +endif ( ) + +#------------------------------------------------------------------------------- +# print final C flags +#------------------------------------------------------------------------------- + +message ( STATUS "CMAKE C flags: " ${CMAKE_C_FLAGS} ) + +#------------------------------------------------------------------------------- +# Demo programs +#------------------------------------------------------------------------------- + +file ( GLOB SOURCES "*.c" ) + +add_executable ( extract_test ${SOURCES} ) + +# Libraries required for Demo programs +target_link_libraries ( extract_test graphblas lagraph m ) + diff --git a/Test/extract/Makefile b/Test/extract/Makefile new file mode 100644 index 0000000000..eee537921e --- /dev/null +++ b/Test/extract/Makefile @@ -0,0 +1,38 @@ +#------------------------------------------------------------------------------- +# Test/extract/Makefile +#------------------------------------------------------------------------------- + +# LAGraph, (... list all authors here) (c) 2019, All Rights Reserved. +# http://graphblas.org See LAGraph/LICENSE for license. + +#------------------------------------------------------------------------------- + +# simple Makefile for LAGraph/Test/extract/extract_test, + +# relies on cmake to do the actual build. Use the CMAKE_OPTIONS argument to +# this Makefile to pass options to cmake. + +# Install LAGraph and GraphBLAS before trying to compile LAGraph. + +JOBS ?= 1 + +# build and run test +default: compile + ./build/extract_test + +# build test +compile: + ( cd build ; cmake $(CMAKE_OPTIONS) .. ; $(MAKE) --jobs=$(JOBS) ) + +# just run cmake; do not compile +cmake: + ( cd build ; cmake $(CMAKE_OPTIONS) .. ; ) + +clean: distclean + +purge: distclean + +# remove all files not in the distribution +distclean: + rm -rf build/* extract_test + diff --git a/Test/extract/build/.gitignore b/Test/extract/build/.gitignore new file mode 100644 index 0000000000..fa2000d455 --- /dev/null +++ b/Test/extract/build/.gitignore @@ -0,0 +1,4 @@ +# Ignore all files here except this file. +* +*/ +!.gitignore diff --git a/Test/extract/extract_test.c b/Test/extract/extract_test.c new file mode 100644 index 0000000000..cf10f2fbc1 --- /dev/null +++ b/Test/extract/extract_test.c @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// LAGraph/Test/extract/extract_test.c: test program for GrB*extractElement +//------------------------------------------------------------------------------ + +/* + LAGraph: graph algorithms based on GraphBLAS + + Copyright 2019 LAGraph Contributors. + + (see Contributors.txt for a full list of Contributors; see + ContributionInstructions.txt for information on how you can Contribute to + this project). + + All Rights Reserved. + + NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH + CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR + PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF + THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH + RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + + Released under a BSD license, please see the LICENSE file distributed with + this Software or contact permission@sei.cmu.edu for full terms. + + Created, in part, with funding and support from the United States + Government. (see Acknowledgments.txt file). + + This program includes and/or can make use of certain third party source + code, object code, documentation and other files ("Third Party Software"). + See LICENSE file for more details. + +*/ + +//------------------------------------------------------------------------------ + +// Contributed by Tim Davis, Texas A&M + +// Usage: extract_test + +#include "LAGraph.h" + +#define LAGRAPH_FREE_ALL \ + GrB_free (&X) ; + +#define CHECK(ok) \ + if (!(ok)) \ + { \ + fprintf (stderr, "fail: %s %d\n", __FILE__, __LINE__) ; \ + printf ("fail: %s %d\n", __FILE__, __LINE__) ; \ + abort ( ) ; \ + } + +int main (int argc, char **argv) +{ + + //-------------------------------------------------------------------------- + // initialize LAGraph and GraphBLAS + //-------------------------------------------------------------------------- + + GrB_Info info ; + GrB_Vector X = NULL ; + LAGraph_init ( ) ; // start LAGraph + + //-------------------------------------------------------------------------- + // construct a nearly-dense vector + //-------------------------------------------------------------------------- + + double tic [2] ; + LAGraph_tic (tic) ; + + GrB_Index n = 64 * 1024 * 1024 ; + printf ("extract test: n = %lu\n", n) ; + LAGr_Vector_new (&X, GrB_UINT64, n) ; + for (uint64_t k = 1 ; k < n ; k++) + { + LAGr_Vector_setElement (X, k, k) ; + } + + double t = LAGraph_toc (tic) ; + printf ("set time %12.6f n/sec %12.6f million\n", t, 1e-6 * ((double) n-1) / t) ; + + LAGraph_tic (tic) ; + GrB_Index ignore ; + LAGr_Vector_nvals (&ignore, X) ; + t = LAGraph_toc (tic) ; + printf ("wait time %12.6f n/sec %12.6f million\n", t, 1e-6 * ((double) n-1) / t) ; + + LAGraph_tic (tic) ; + GxB_print (X, GxB_SHORT) ; + t = LAGraph_toc (tic) ; + printf ("check time %12.6f n/sec %12.6f million\n", t, 1e-6 * ((double) n-1) / t) ; + + //-------------------------------------------------------------------------- + // test binary searches + //-------------------------------------------------------------------------- + + uint64_t x ; + + for (uint64_t k = 1 ; k < n ; k++) + { + LAGr_Vector_extractElement (&x, X, k) ; + CHECK (x == k) ; + } + + t = LAGraph_toc (tic) ; + printf ("extract time %12.6f n/sec %12.6f million\n", t, 1e-6 * ((double) n-1) / t) ; + + info = GrB_Vector_extractElement (&x, X, 0) ; + CHECK (info == GrB_NO_VALUE) ; + + LAGRAPH_FREE_ALL ; + LAGraph_finalize ( ) ; + return (GrB_SUCCESS) ; +} + diff --git a/Test/extract/output_330draft1.txt b/Test/extract/output_330draft1.txt new file mode 100644 index 0000000000..a88d87fa5d --- /dev/null +++ b/Test/extract/output_330draft1.txt @@ -0,0 +1,62 @@ +( cd build ; cmake .. ; make --jobs=1 ) +-- CMAKE build type: Release +-- CMAKE C Flags release: -O3 -DNDEBUG +-- CMAKE compiler ID: GNU +-- CMAKE thread library: -lpthread +-- CMAKE have pthreads: 1 +-- CMAKE have Win32 pthreads: +-- CMAKE have OpenMP: TRUE +-- Automatic selection of synchronization method +-- Using OpenMP to synchronize user threads +-- CMAKE C flags: -std=c11 -lm -Wno-pragmas -O3 -DNDEBUG -fopenmp -DUSER_OPENMP_THREADS -DHAVE_PTHREADS +-- Configuring done +-- Generating done +-- Build files have been written to: /home/davis/sparse/LAGraph/Test/extract/build +make[1]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[2]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[3]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[3]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +[100%] Built target extract_test +make[2]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[1]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +./build/extract_test +extract test: n = 67108864 +set time 2.544358 n/sec 26.375563 million +wait time 0.022595 n/sec 2970.039410 million + + 67108864x1 GraphBLAS uint64_t vector, sparse by col: + X, 67108863 entries + + (1,0) 1 + (2,0) 2 + (3,0) 3 + (4,0) 4 + (5,0) 5 + (6,0) 6 + (7,0) 7 + (8,0) 8 + (9,0) 9 + (10,0) 10 + (11,0) 11 + (12,0) 12 + (13,0) 13 + (14,0) 14 + (15,0) 15 + (16,0) 16 + (17,0) 17 + (18,0) 18 + (19,0) 19 + (20,0) 20 + (21,0) 21 + (22,0) 22 + (23,0) 23 + (24,0) 24 + (25,0) 25 + (26,0) 26 + (27,0) 27 + (28,0) 28 + (29,0) 29 + (30,0) 30 + ... +check time 0.310778 n/sec 215.938521 million +extract time 5.386432 n/sec 12.458871 million diff --git a/Test/extract/output_330draft4.txt b/Test/extract/output_330draft4.txt new file mode 100644 index 0000000000..eb30cbbc9c --- /dev/null +++ b/Test/extract/output_330draft4.txt @@ -0,0 +1,62 @@ +( cd build ; cmake .. ; make --jobs=1 ) +-- CMAKE build type: Release +-- CMAKE C Flags release: -O3 -DNDEBUG +-- CMAKE compiler ID: GNU +-- CMAKE thread library: -lpthread +-- CMAKE have pthreads: 1 +-- CMAKE have Win32 pthreads: +-- CMAKE have OpenMP: TRUE +-- Automatic selection of synchronization method +-- Using OpenMP to synchronize user threads +-- CMAKE C flags: -std=c11 -lm -Wno-pragmas -O3 -DNDEBUG -fopenmp -DUSER_OPENMP_THREADS -DHAVE_PTHREADS +-- Configuring done +-- Generating done +-- Build files have been written to: /home/davis/sparse/LAGraph/Test/extract/build +make[1]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[2]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[3]: Entering directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[3]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +[100%] Built target extract_test +make[2]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +make[1]: Leaving directory '/home/davis/sparse/LAGraph/Test/extract/build' +./build/extract_test +extract test: n = 67108864 +set time 2.295970 n/sec 29.228981 million +wait time 0.027256 n/sec 2462.127882 million + + 67108864x1 GraphBLAS uint64_t vector, sparse by col: + X, 67108863 entries + + (1,0) 1 + (2,0) 2 + (3,0) 3 + (4,0) 4 + (5,0) 5 + (6,0) 6 + (7,0) 7 + (8,0) 8 + (9,0) 9 + (10,0) 10 + (11,0) 11 + (12,0) 12 + (13,0) 13 + (14,0) 14 + (15,0) 15 + (16,0) 16 + (17,0) 17 + (18,0) 18 + (19,0) 19 + (20,0) 20 + (21,0) 21 + (22,0) 22 + (23,0) 23 + (24,0) 24 + (25,0) 25 + (26,0) 26 + (27,0) 27 + (28,0) 28 + (29,0) 29 + (30,0) 30 + ... +check time 0.278284 n/sec 241.152681 million +extract time 3.593726 n/sec 18.673897 million