Skip to content

Commit

Permalink
Compile sparse13 as its own static library
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Aug 8, 2023
1 parent b786c36 commit afb567d
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 86 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ endif()
# =============================================================================
# Add project directories AFTER CMake modules
# =============================================================================
add_subdirectory(src/sparse13)
add_subdirectory(src/gnu)
add_subdirectory(src/nrniv)

Expand Down
17 changes: 0 additions & 17 deletions cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,6 @@ set(MESCH_FILES_LIST

set(SPARSE_FILES_LIST bksub.cpp getelm.cpp lineq.cpp prmat.cpp subrows.cpp)

# sparse13 matrix sources
set(SPARSE13_FILES_LIST
spalloc.cpp
spbuild.cpp
spfactor.cpp
spoutput.cpp
spsolve.cpp
sputils.cpp
cspalloc.cpp
cspbuild.cpp
cspfactor.cpp
cspoutput.cpp
cspsolve.cpp
csputils.cpp)

# scopmath sources
set(SCOPMATH_FILES_LIST
abort.cpp
Expand Down Expand Up @@ -546,8 +531,6 @@ nrn_create_file_list(NRN_PARALLEL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sundials/s
nvector_parallel.c)
nrn_create_file_list(NRN_MESCH_SRC_FILES ${PROJECT_SOURCE_DIR}/src/mesch ${MESCH_FILES_LIST})
nrn_create_file_list(NRN_SPARSE_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sparse ${SPARSE_FILES_LIST})
nrn_create_file_list(NRN_SPARSE13_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sparse13
${SPARSE13_FILES_LIST})
nrn_create_file_list(NRN_SCOPMATH_SRC_FILES ${PROJECT_SOURCE_DIR}/src/scopmath
${SCOPMATH_FILES_LIST})
nrn_create_file_list(NRN_NRNMPI_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi ${NRNMPI_FILES_LIST})
Expand Down
2 changes: 1 addition & 1 deletion src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ set(NRN_NRNIV_LIB_SRC_FILES
${NRN_MODFILE_CPP}
${NRN_SCOPMATH_SRC_FILES}
${NRN_SPARSE_SRC_FILES}
${NRN_SPARSE13_SRC_FILES}
${NRN_SUNDIALS_SRC_FILES})

if(NRN_ENABLE_MPI)
Expand Down Expand Up @@ -411,6 +410,7 @@ include_directories(${NRN_INCLUDE_DIRS})
# =============================================================================
add_library(nrniv_lib ${NRN_LIBRARY_TYPE} ${NRN_NRNIV_LIB_SRC_FILES})
target_link_libraries(nrniv_lib nrngnu)
target_link_libraries(nrniv_lib sparse13)
cpp_cc_configure_sanitizers(TARGET nrniv_lib)
# Source-directory .cpp needs to find generated .hpp.
target_include_directories(nrniv_lib PUBLIC "${NRN_OC_GEN}")
Expand Down
16 changes: 16 additions & 0 deletions src/sparse13/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_library(
sparse13 STATIC
spalloc.cpp
spbuild.cpp
spfactor.cpp
spoutput.cpp
spsolve.cpp
sputils.cpp
cspalloc.cpp
cspbuild.cpp
cspfactor.cpp
cspoutput.cpp
cspsolve.cpp
csputils.cpp
)
set_property(TARGET sparse13 PROPERTY POSITION_INDEPENDENT_CODE ON)
3 changes: 0 additions & 3 deletions src/sparse13/spalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX ALLOCATION MODULE
*
Expand Down
3 changes: 0 additions & 3 deletions src/sparse13/spbuild.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX BUILD MODULE
*
Expand Down
32 changes: 0 additions & 32 deletions src/sparse13/spconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,45 +415,13 @@
* do not provide the standard header files yet.
*/
#endif
#if defined(HAVE_LIMITS_H)
#include <float.h>
#include <limits.h>
#define MACHINE_RESOLUTION DBL_EPSILON
#define LARGEST_REAL DBL_MAX
#define SMALLEST_REAL DBL_MIN
#define LARGEST_SHORT_INTEGER SHRT_MAX
#define LARGEST_LONG_INTEGER LONG_MAX
#else /* do not have limits.h */ /* NOT defined(__STDC__) */

/* VAX machine constants */
#ifdef vax
#define MACHINE_RESOLUTION 6.93889e-18
#define LARGEST_REAL 1.70141e+38
#define SMALLEST_REAL 2.938743e-39
#define LARGEST_SHORT_INTEGER 32766
#define LARGEST_LONG_INTEGER 2147483646
#endif

/* hp9000 machine constants */
#ifdef hpux
/* These values are correct for hp9000/300. Should be correct for others. */
#define MACHINE_RESOLUTION 8.9e-15
#define LARGEST_REAL 1.79769313486231e+308
#define SMALLEST_REAL 2.22507385850721e-308
#define LARGEST_SHORT_INTEGER 32766
#define LARGEST_LONG_INTEGER 2147483646
#endif

/* Sun machine constants */
#ifdef sun
/* These values are rumored to be the correct values. */
#define MACHINE_RESOLUTION 8.9e-15
#define LARGEST_REAL 1.79769313486231e+308
#define SMALLEST_REAL 2.22507385850721e-308
#define LARGEST_SHORT_INTEGER 32766
#define LARGEST_LONG_INTEGER 2147483646
#endif
#endif /* NOT defined(__STDC__) */

/*
* ANNOTATION
Expand Down
2 changes: 1 addition & 1 deletion src/sparse13/spdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
* MEMORY ALLOCATION
*/
#if 1
#include <spmatrix.h>
#include "spmatrix.h"
#include <stdlib.h>
#else
#if !defined(__MWERKS__)
Expand Down
30 changes: 14 additions & 16 deletions src/sparse13/spfactor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX FACTORIZATION MODULE
*
Expand Down Expand Up @@ -67,6 +64,7 @@ static char RCSid[] = "@(#)$Header$";
#include "spconfig.h"
#include "spdefs.h"
#include "spmatrix.h"
#include <climits>

/* avoid "declared implicitly `extern' and later `static' " warnings. */
static int FactorComplexMatrix(MatrixPtr Matrix);
Expand Down Expand Up @@ -896,10 +894,10 @@ static void MarkowitzProducts(MatrixPtr Matrix, int Step)

for (I = Step; I <= Size; I++) {
/* If chance of overflow, use real numbers. */
if ((*pMarkowitzRow > LARGEST_SHORT_INTEGER AND * pMarkowitzCol != 0) OR(*pMarkowitzCol > LARGEST_SHORT_INTEGER AND * pMarkowitzRow != 0)) {
if ((*pMarkowitzRow > SHRT_MAX AND * pMarkowitzCol != 0) OR(*pMarkowitzCol > SHRT_MAX AND * pMarkowitzRow != 0)) {
fProduct = (double)(*pMarkowitzRow++) * (double)(*pMarkowitzCol++);
if (fProduct >= (double)LARGEST_LONG_INTEGER)
*pMarkowitzProduct++ = LARGEST_LONG_INTEGER;
if (fProduct >= (double)LONG_MAX)
*pMarkowitzProduct++ = LONG_MAX;
else
*pMarkowitzProduct++ = fProduct;
} else {
Expand Down Expand Up @@ -1228,7 +1226,7 @@ static ElementPtr QuicklySearchDiagonal(MatrixPtr Matrix, int Step)

/* Begin `QuicklySearchDiagonal'. */
NumberOfTies = -1;
MinMarkowitzProduct = LARGEST_LONG_INTEGER;
MinMarkowitzProduct = LONG_MAX;
pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size + 2]);
Matrix->MarkowitzProd[Matrix->Size + 1] = Matrix->MarkowitzProd[Step];

Expand Down Expand Up @@ -1409,7 +1407,7 @@ static ElementPtr QuicklySearchDiagonal(MatrixPtr Matrix, int Step)

/* Begin `QuicklySearchDiagonal'. */
ChosenPivot = NULL;
MinMarkowitzProduct = LARGEST_LONG_INTEGER;
MinMarkowitzProduct = LONG_MAX;
pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size + 2]);
Matrix->MarkowitzProd[Matrix->Size + 1] = Matrix->MarkowitzProd[Step];

Expand Down Expand Up @@ -1563,7 +1561,7 @@ static ElementPtr SearchDiagonal(MatrixPtr Matrix, int Step)

/* Begin `SearchDiagonal'. */
ChosenPivot = NULL;
MinMarkowitzProduct = LARGEST_LONG_INTEGER;
MinMarkowitzProduct = LONG_MAX;
pMarkowitzProduct = &(Matrix->MarkowitzProd[Size + 2]);
Matrix->MarkowitzProd[Size + 1] = Matrix->MarkowitzProd[Step];

Expand Down Expand Up @@ -1674,7 +1672,7 @@ static ElementPtr SearchEntireMatrix(MatrixPtr Matrix, int Step)
/* Begin `SearchEntireMatrix'. */
ChosenPivot = NULL;
LargestElementMag = 0.0;
MinMarkowitzProduct = LARGEST_LONG_INTEGER;
MinMarkowitzProduct = LONG_MAX;

/* Start search of matrix on column by column basis. */
for (I = Step; I <= Size; I++) {
Expand Down Expand Up @@ -2570,10 +2568,10 @@ static void UpdateMarkowitzNumbers(MatrixPtr Matrix, ElementPtr pPivot)
--MarkoRow[Row];

/* Form Markowitz product while being cautious of overflows. */
if ((MarkoRow[Row] > LARGEST_SHORT_INTEGER AND MarkoCol[Row] != 0) OR(MarkoCol[Row] > LARGEST_SHORT_INTEGER AND MarkoRow[Row] != 0)) {
if ((MarkoRow[Row] > SHRT_MAX AND MarkoCol[Row] != 0) OR(MarkoCol[Row] > SHRT_MAX AND MarkoRow[Row] != 0)) {
Product = MarkoCol[Row] * MarkoRow[Row];
if (Product >= (double)LARGEST_LONG_INTEGER)
Matrix->MarkowitzProd[Row] = LARGEST_LONG_INTEGER;
if (Product >= (double)LONG_MAX)
Matrix->MarkowitzProd[Row] = LONG_MAX;
else
Matrix->MarkowitzProd[Row] = Product;
} else
Expand All @@ -2587,10 +2585,10 @@ static void UpdateMarkowitzNumbers(MatrixPtr Matrix, ElementPtr pPivot)
--MarkoCol[Col];

/* Form Markowitz product while being cautious of overflows. */
if ((MarkoRow[Col] > LARGEST_SHORT_INTEGER AND MarkoCol[Col] != 0) OR(MarkoCol[Col] > LARGEST_SHORT_INTEGER AND MarkoRow[Col] != 0)) {
if ((MarkoRow[Col] > SHRT_MAX AND MarkoCol[Col] != 0) OR(MarkoCol[Col] > SHRT_MAX AND MarkoRow[Col] != 0)) {
Product = MarkoCol[Col] * MarkoRow[Col];
if (Product >= (double)LARGEST_LONG_INTEGER)
Matrix->MarkowitzProd[Col] = LARGEST_LONG_INTEGER;
if (Product >= (double)LONG_MAX)
Matrix->MarkowitzProd[Col] = LONG_MAX;
else
Matrix->MarkowitzProd[Col] = Product;
} else
Expand Down
8 changes: 3 additions & 5 deletions src/sparse13/spoutput.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX OUTPUT MODULE
*
Expand Down Expand Up @@ -57,6 +54,7 @@ static char RCSid[] = "$Header$";
#include "spconfig.h"
#include "spdefs.h"
#include "spmatrix.h"
#include <cfloat>

#if DOCUMENTATION

Expand Down Expand Up @@ -184,7 +182,7 @@ void spPrint(char* eMatrix, int PrintReordered, int Data, int Header)
else
printf("Matrix before factorization:\n");

SmallestElement = LARGEST_REAL;
SmallestElement = DBL_MAX;
SmallestDiag = SmallestElement;
}

Expand Down Expand Up @@ -667,7 +665,7 @@ int spFileStats(char* eMatrix, char* File, char* Label)
/* Search matrix. */
NumberOfElements = 0;
LargestElement = 0.0;
SmallestElement = LARGEST_REAL;
SmallestElement = DBL_MAX;

for (I = 1; I <= Size; I++) {
pElement = Matrix->FirstInCol[I];
Expand Down
3 changes: 0 additions & 3 deletions src/sparse13/spsolve.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX SOLVE MODULE
*
Expand Down
8 changes: 3 additions & 5 deletions src/sparse13/sputils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <../../nrnconf.h>
#endif
/*
* MATRIX UTILITY MODULE
*
Expand Down Expand Up @@ -69,6 +66,7 @@ static char RCSid[] = "@(#)$Header$";
#include "spconfig.h"
#include "spdefs.h"
#include "spmatrix.h"
#include <cfloat>

extern void spcLinkRows(MatrixPtr);
extern void spcRowExchange(MatrixPtr, int row1, int row2);
Expand Down Expand Up @@ -1985,8 +1983,8 @@ RealNumber spRoundoff(char* eMatrix, RealNumber Rho)
Reid = 3.01 * Matrix->Size;

if (Gear < Reid)
return (MACHINE_RESOLUTION * Rho * Gear);
return (DBL_EPSILON * Rho * Gear);
else
return (MACHINE_RESOLUTION * Rho * Reid);
return (DBL_EPSILON * Rho * Reid);
}
#endif

0 comments on commit afb567d

Please sign in to comment.