diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f565e9bad9b622c8d74bdabd91ff47a368ce704..3d09034c24b9f7a27397c9e23ad5a7e90a70bae7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ project (SPM C Fortran) # Check if compiled independently or within another project if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - set( BUILD_SUBPROJECT OFF ) + set( BUILD_AS_SUBPROJECT OFF ) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) @@ -22,8 +22,7 @@ if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) endif(NOT CMAKE_BUILD_TYPE) if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules) - set( MORSE_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules ) - list(APPEND CMAKE_MODULE_PATH ${MORSE_CMAKE_MODULE_PATH}) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/morse_cmake/modules) include(MorseInit) else() message(FATAL_ERROR "Submodule cmake_morse not initialized - run `git submodule update --init`") @@ -33,8 +32,37 @@ if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) enable_testing() include(CTest) + include (CheckCCompilerFlag) + + # Set warnings for debug builds + check_c_compiler_flag( "-Wall" HAVE_WALL ) + if( HAVE_WALL ) + set( C_WFLAGS "${C_WFLAGS} -Wall" ) + endif( HAVE_WALL ) + check_c_compiler_flag( "-Wextra" HAVE_WEXTRA ) + if( HAVE_WEXTRA ) + set( C_WFLAGS "${C_WFLAGS} -Wextra" ) + endif( HAVE_WEXTRA ) + + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WFLAGS}" ) + + # add gdb symbols in debug and relwithdebinfo + check_c_compiler_flag( "-g3" HAVE_G3 ) + if( HAVE_G3 ) + set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3" ) + set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -g3" ) + else() + set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0" ) + endif( HAVE_G3 ) + else() - set( BUILD_SUBPROJECT ON ) + set( BUILD_AS_SUBPROJECT ON ) + + # Check if within pastix which provides Scotch + if (PASTIX_ORDERING_SCOTCH) + set(HAVE_SCOTCH ON) + endif() + endif() # Define a subproject name fr ctest @@ -84,22 +112,33 @@ include(RulesPrecisions) ### System parameter detection include(CheckSystem) -# PaStiX depends on CBLAS -#---------------------------- -find_package(CBLAS) # Should be REQUIRED for BLAS sequential only -if(CBLAS_FOUND) - message(STATUS "cblas: ${CBLAS_INCLUDE_DIRS}") - include_directories(${CBLAS_INCLUDE_DIRS}) -endif() - -find_package(LAPACKE) # Should be also REQUIRED +# SPM depends on Lapacke and CBLAS +#--------------------------------- +find_package(LAPACKE REQUIRED) if(LAPACKE_FOUND) message(STATUS "lapacke: ${LAPACKE_INCLUDE_DIRS}") include_directories(${LAPACKE_INCLUDE_DIRS}) endif() -#Configuration header -#-------------------- +find_package(CBLAS REQUIRED) +if(CBLAS_FOUND) + message(STATUS "cblas: ${CBLAS_INCLUDE_DIRS}") + include_directories(${CBLAS_INCLUDE_DIRS}) +endif() + +### Store dependencies not handled with pkg-config +set( DEPS_LIBRARIES + ${LAPACKE_LIBRARIES_DEP} + ${CBLAS_LIBRARIES_DEP} + ) + +list(APPEND CMAKE_INSTALL_RPATH + ${LAPACKE_LIBRARY_DIRS_DEP} + ${CBLAS_LIBRARY_DIRS_DEP} + ) + +# Configuration header +#--------------------- configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/include/spm_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/spm_config.h") @@ -108,10 +147,8 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/spm_config.h" DESTINATION include include_directories(include) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src") include_directories("${CMAKE_CURRENT_BINARY_DIR}/src") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/drivers") ### reset variables -set(generated_sources "") set(generated_headers "") ### Generate the headers in all precisions @@ -134,6 +171,8 @@ add_custom_target(spm_headers_tgt DEPENDS ${spm_headers} ) ### Generate the sources in all precisions +set(generated_sources "") + set(SOURCES src/z_spm.c src/z_spm_2dense.c @@ -186,10 +225,8 @@ add_library(spm ) target_link_libraries(spm - ${LAPACKE_LIBRARIES} - ${LAPACK_SEQ_LIBRARIES} - ${CBLAS_LIBRARIES} - ${BLAS_SEQ_LIBRARIES} + ${LAPACKE_LIBRARIES_DEP} + ${CBLAS_LIBRARIES_DEP} ) add_dependencies(spm diff --git a/cmake_modules/morse_cmake b/cmake_modules/morse_cmake index f4ead635e331c6a43b81d9e0a56b082fe47be36c..1deddb2781f62dbbf0ee9199f569e49f7346397a 160000 --- a/cmake_modules/morse_cmake +++ b/cmake_modules/morse_cmake @@ -1 +1 @@ -Subproject commit f4ead635e331c6a43b81d9e0a56b082fe47be36c +Subproject commit 1deddb2781f62dbbf0ee9199f569e49f7346397a diff --git a/include/spm.h b/include/spm.h index 58a9689dd1a10cc6289702d0319a7a4ef20e7145..dc66ea3dafa8803d4db944bef328c38d9b65f2f8 100644 --- a/include/spm.h +++ b/include/spm.h @@ -132,6 +132,8 @@ void spmIntSort1Asc1( void * const pbase, const spm_int_t n ); void spmIntSort2Asc1( void * const pbase, const spm_int_t n ); void spmIntSort2Asc2( void * const pbase, const spm_int_t n ); +void spmIntMSortIntAsc(void ** const pbase, const spm_int_t n); + /** * @} * @name SPM IO subroutines diff --git a/include/spm_config.h.in b/include/spm_config.h.in index 3301b6c0450e78c5c0f37349dd990d88b2d372ed..64116e78a2fe790e06bcdbc41137dab6144c7942 100644 --- a/include/spm_config.h.in +++ b/include/spm_config.h.in @@ -44,6 +44,9 @@ /* Datatypes used */ #cmakedefine SPM_INT64 +/* Exploit the scotch version from the library compiling spm */ +#cmakedefine HAVE_SCOTCH + #if defined(HAVE_FALLTHROUGH) #define spm_attr_fallthrough __attribute__((fallthrough)) #else diff --git a/src/common.h b/src/common.h index 76c22ea74ed8f519e894d4ecbb860b753506b3cb..896a9905d6aab4667da5f4f30053b2e1acd30171 100644 --- a/src/common.h +++ b/src/common.h @@ -111,6 +111,5 @@ spm_cleanenv( char *str ) { #endif - #endif /* _spm_common_h_ */ diff --git a/src/spm_integers.c b/src/spm_integers.c index 33d98444ff0f91ee83b573e017c1e1326bfc642d..573da54f4ecfb54b55203336e8b843d4411312ad 100644 --- a/src/spm_integers.c +++ b/src/spm_integers.c @@ -238,9 +238,6 @@ void spmIntSort3Asc1(void *const pbase, const spm_int_t n); * ******************************************************************************* */ -/* Declare here for now, because unused */ -void spmIntMSortIntAsc(void ** const pbase, const spm_int_t n); - #ifndef DOXYGEN_SHOULD_SKIP_THIS #define INTSORTNAME spmIntMSortIntAsc #define INTSORTSIZE(x) (sizeof (spm_int_t)) diff --git a/src/z_spm.h b/src/z_spm.h index 27254c73f878723153392807c2053289aac3d90e..d00989fb01098b479a8c93c911db904ac4934de3 100644 --- a/src/z_spm.h +++ b/src/z_spm.h @@ -52,7 +52,7 @@ double z_spmNorm( int ntype, const spmatrix_t *spm ); /** * Extra routines */ -void z_spmSort( spmatrix_t *spm ); +void z_spmSort( spmatrix_t *spm ); spm_int_t z_spmMergeDuplicate( spmatrix_t *spm ); spm_int_t z_spmSymmetrize( spmatrix_t *spm ); @@ -66,8 +66,8 @@ void z_spmDensePrint( FILE *f, spm_int_t m, spm_int_t n, const spm_complex64_t * void z_spmPrint( FILE *f, const spmatrix_t *spm ); spmatrix_t *z_spmExpand(const spmatrix_t *spm); -void z_spmDofExtend(spmatrix_t *spm); -void z_spmScal( const double alpha, spmatrix_t *spm ); +void z_spmDofExtend(spmatrix_t *spm); +void z_spmScal( const double alpha, spmatrix_t *spm ); #endif /* _z_spm_h_ */ diff --git a/src/z_spm_genrhs.c b/src/z_spm_genrhs.c index 8e1227a46b2cec1c2e803bc0915ab745e00a9854..7016a0c0af84d84b455af58d9f19fabdd5338c69 100644 --- a/src/z_spm_genrhs.c +++ b/src/z_spm_genrhs.c @@ -131,7 +131,7 @@ z_spmRndVect( double scale, int m, int n, spm_complex64_t *A, int lda, for (i = 0; i < m; ++i) { *tmp = (0.5f - ran * RndF_Mul) * scale; ran = Rnd64_A * ran + Rnd64_C; -#ifdef COMPLEX +#if defined(PRECISION_z) || defined(PRECISION_c) *tmp += (I*(0.5f - ran * RndF_Mul)) * scale; ran = Rnd64_A * ran + Rnd64_C; #endif @@ -368,7 +368,8 @@ z_spmCheckAxb( spm_fixdbl_t eps, int nrhs, const spm_complex64_t *zx = (const spm_complex64_t *)x; spm_complex64_t *zx0 = (spm_complex64_t *)x0; spm_complex64_t *zb = (spm_complex64_t *)b; - double normA, normB, normX, normX0, normR; + double *nb2 = malloc( nrhs * sizeof(double) ); + double normA, normB, normX, normX0, normR, normR2; double backward, forward; int failure = 0; int i; @@ -394,6 +395,8 @@ z_spmCheckAxb( spm_fixdbl_t eps, int nrhs, normB = (norm > normB ) ? norm : normB; norm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, 1, zx + i * ldx, ldx ); normX = (norm > normX ) ? norm : normX; + + nb2[i] = cblas_dznrm2( spm->n, zb + i * ldb, 1 ); } printf( " || A ||_1 %e\n" " max(|| b_i ||_oo) %e\n" @@ -406,22 +409,27 @@ z_spmCheckAxb( spm_fixdbl_t eps, int nrhs, spmMatMat( SpmNoTrans, nrhs, &mzone, spm, x, ldx, &zone, b, ldb ); normR = 0.; + normR2 = 0.; backward = 0.; failure = 0; for( i=0; i<nrhs; i++ ) { double nx = cblas_dzasum( spm->n, zx + i * ldx, 1 ); double nr = cblas_dzasum( spm->n, zb + i * ldb, 1 ); + double nr2 = cblas_dznrm2( spm->n, zb + i * ldb, 1 ) / nb2[i]; double back = ((nr / normA) / nx) / eps; int fail = 0; normR = (nr > normR ) ? nr : normR; + normR2 = (nr2 > normR2 ) ? nr2 : normR2; backward = (back > backward) ? back : backward; fail = isnan(nr) || isinf(nr) || isnan(back) || isinf(back) || (back > 1.e2); if ( fail ) { - printf( " || b_%d - A x_%d ||_1 %e\n" + printf( " || b_%d - A x_%d ||_2 / || b_%d ||_2 %e\n" + " || b_%d - A x_%d ||_1 %e\n" " || b_%d - A x_%d ||_1 / (||A||_1 * ||x_%d||_oo * eps) %e (%s)\n", + i, i, i, nr2, i, i, nr, i, i, i, back, fail ? "FAILED" : "SUCCESS" ); @@ -430,11 +438,14 @@ z_spmCheckAxb( spm_fixdbl_t eps, int nrhs, failure = failure || fail; } - printf( " max(|| b_i - A x_i ||_1) %e\n" + printf( " max(|| b_i - A x_i ||_2 / || b_i ||_2) %e\n" + " max(|| b_i - A x_i ||_1) %e\n" " max(|| b_i - A x_i ||_1 / (||A||_1 * ||x_i||_oo * eps)) %e (%s)\n", - normR, backward, + normR2, normR, backward, failure ? "FAILED" : "SUCCESS" ); + free(nb2); + /** * Compute r = x0 - x */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ff6480bc2b82ecebfa5ae8a3183ed688a3d343b3..608ab0ab7a78604831546e6f8c8741a141445252 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,8 +34,8 @@ add_library(spm_test target_link_libraries( spm_test spm - ${LAPACKE_LIBRARIES} - ${LAPACK_SEQ_LIBRARIES} ) + ${LAPACKE_LIBRARIES_DEP} + ${CBLAS_LIBRARIES_DEP} ) ## Generate all test executables set (TESTS