Skip to content

Commit

Permalink
CHOLMOD METIS interface: use GKRAND with threadprivate
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Sep 5, 2023
1 parent d51c90f commit f3ac3ea
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 3 deletions.
Binary file modified AMD/Doc/AMD_UserGuide.pdf
Binary file not shown.
Binary file modified CAMD/Doc/CAMD_UserGuide.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions CHOLMOD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ if ( OPENMP_FOUND )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS} " )
include_directories ( ${OpenMP_C_INCLUDE_DIRS} )
else ( )
# to fix METIS: use threadprivate variables for GKRAND instead globals,
# so multiple user threads can call cholmod_analyze in parallel on
# different matrices, and avoid global locking of the system rand.
include ( SuiteSparse__thread )
endif ( )

# libm:
Expand Down
Binary file modified CHOLMOD/Doc/CHOLMOD_UserGuide.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion CHOLMOD/Doc/CHOLMOD_UserGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
\end{abstract}
%-------------------------------------------------------------------------------

CHOLMOD Copyright\copyright 2005-2022 by Timothy A. Davis, All Rights Reserved.
CHOLMOD Copyright\copyright 2005-2023 by Timothy A. Davis, All Rights Reserved.
Portions are also copyrighted by William W. Hager (the {\tt Modify} Module),
and the University of Florida (the {\tt Partition} and {\tt Core} Modules).
All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions CHOLMOD/Doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FIXME DATE, 2023: version 4.2.0
cholmod_metis_wrapper.c, Tcov/memory.c.
* support for SPQR: minor changes to support SPQR v4.2.0 with 32-bit
integers; no change to user-visible API.
* METIS now using GKRAND: with threadprivate state variables, to
avoid global system lock when using CHOLMON on many user threads

June 16, 2023: version 4.0.4

Expand Down
7 changes: 6 additions & 1 deletion CHOLMOD/Partition/cholmod_metis_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CHOLMOD/Partition/cholmod_metis_wrapper.h: METIS renaming for CHOLMOD
//------------------------------------------------------------------------------

// CHOLMOD/Partition Module. Copyright (C) 2005-2022, University of Florida.
// CHOLMOD/Partition Module. Copyright (C) 2005-2023, University of Florida.
// All Rights Reserved. Author: Timothy A. Davis.
// SPDX-License-Identifier: LGPL-2.1+

Expand All @@ -11,6 +11,11 @@
#ifndef CHOLMOD_METIS_WRAP_H
#define CHOLMOD_METIS_WRAP_H

// always use GKRAND instead of the system rand in METIS
#ifndef USE_GKRAND
#define USE_GKRAND
#endif

#if defined ( __GNUC__ ) && !defined ( __clang__ )
// disable memcpy warnings:
#pragma GCC diagnostic ignored "-Wstringop-overflow="
Expand Down
30 changes: 30 additions & 0 deletions CHOLMOD/SuiteSparse_metis/GKlib/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,41 @@ GK_MKRANDOM(gk_z, size_t, ssize_t)
#define UM 0xFFFFFFFF80000000ULL /* Most significant 33 bits */
#define LM 0x7FFFFFFFULL /* Least significant 31 bits */

// added by Tim Davis for CHOLMOD: mt and mti state variables threadprivate
#if defined ( _OPENMP )

// OpenMP threadprivate is preferred
static uint64_t mt[NN];
static int mti=NN+1;
#pragma omp threadprivate (mt,mti)

#elif defined ( HAVE_KEYWORD__THREAD )

// gcc and many other compilers support the __thread keyword
__thread static uint64_t mt[NN];
__thread static int mti=NN+1;

#elif defined ( HAVE_KEYWORD__DECLSPEC_THREAD )

// Windows: __declspec (thread)
__declspec ( thread ) static uint64_t mt[NN];
__declspec ( thread ) static int mti=NN+1;

#elif defined ( HAVE_KEYWORD__THREAD_LOCAL )

// ANSI C11 threads
#include <threads.h>
_Thread_local static uint64_t mt[NN];
_Thread_local static int mti=NN+1;

#else
// original METIS uses global state: this is not thread-safe:
/* The array for the state vector */
static uint64_t mt[NN];
/* mti==NN+1 means mt[NN] is not initialized */
static int mti=NN+1;
#endif

#endif /* USE_GKRAND */

/* initializes mt[NN] with a seed */
Expand Down
Binary file modified GraphBLAS/Doc/GraphBLAS_UserGuide.pdf
Binary file not shown.
Binary file modified KLU/Doc/KLU_UserGuide.pdf
Binary file not shown.
Binary file modified LDL/Doc/ldl_userguide.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ demos:
# Create the PDF documentation
docs:
( cd GraphBLAS && $(MAKE) docs )
( cd Mongoose && $(MAKE) docs )
# ( cd Mongoose && $(MAKE) docs )
( cd AMD && $(MAKE) docs )
( cd CAMD && $(MAKE) docs )
( cd KLU && $(MAKE) docs )
Expand Down
Binary file modified SPEX/Doc/SPEX_UserGuide.pdf
Binary file not shown.
72 changes: 72 additions & 0 deletions SuiteSparse_config/SuiteSparse__thread.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#-------------------------------------------------------------------------------
# GraphBLAS/cmake_modules/SuiteSparse__thread.cmake
#-------------------------------------------------------------------------------

# Copyright (c) 2017-2023, Timothy A. Davis. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

#-------------------------------------------------------------------------------

# determine if the __thread keyword is available, which is an extension by
# gcc but supported by many compilers, to indicate thread-local-storage.

include ( CheckCSourceRuns )

set ( thread_src
" #include <stdio.h>
__thread int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )

set ( declspec_thread_src
" #include <stdio.h>
__declspec ( thread ) int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )

set ( thread_local_src
" #include <stdio.h>
#include <threads.h>
_Thread_local int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )

check_c_source_runs ( "${declspec_thread_src}" HAVE_KEYWORD__DECLSPEC_THREAD )

check_c_source_runs ( "${thread_src}" HAVE_KEYWORD__THREAD )

check_c_source_runs ( "${thread_local_src}" HAVE_KEYWORD__THREAD_LOCAL )

if ( HAVE_KEYWORD__DECLSPEC_THREAD )
add_compile_definitions ( HAVE_KEYWORD__DECLSPEC_THREAD )
message ( STATUS "__declspec(thread) keyword: available" )
else ( )
message ( STATUS "__declspec(thread) keyword: not available" )
endif ( )

if ( HAVE_KEYWORD__THREAD )
add_compile_definitions ( HAVE_KEYWORD__THREAD )
message ( STATUS "__thread keyword: available" )
else ( )
message ( STATUS "__thread keyword: not available" )
endif ( )

if ( HAVE_KEYWORD__THREAD_LOCAL )
add_compile_definitions ( HAVE_KEYWORD__THREAD_LOCAL )
message ( STATUS "_Thread_local keyword: available" )
else ( )
message ( STATUS "_Thread_local_thread keyword: not available" )
endif ( )

Binary file modified UMFPACK/Doc/UMFPACK_QuickStart.pdf
Binary file not shown.
Binary file modified UMFPACK/Doc/UMFPACK_UserGuide.pdf
Binary file not shown.

1 comment on commit f3ac3ea

@DrTimothyAldenDavis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #375

Please sign in to comment.