Commit 572634aa authored by Pavel Burovskiy's avatar Pavel Burovskiy

Adding support to LibSmv library

parent 11e620a0
......@@ -81,7 +81,10 @@ MARK_AS_ADVANCED(NEKTAR_USE_EXPRESSION_TEMPLATES)
OPTION(NEKTAR_USE_BLAS_LAPACK "Use Blas and lapack routines." ON)
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_OPENBLAS
"Use OpenBLAS library as a substitute to native BLAS." OFF
"NEKTAR_USE_BLAS_LAPACK" OFF)
"NEKTAR_USE_BLAS_LAPACK" OFF)
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_SMV
"Use LibSMV library for faster small matrix-vector multiplies." OFF
"NEKTAR_USE_BLAS_LAPACK" OFF)
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_ACML
"Use the AMD Core Math Library (ACML) for BLAS and Lapack support." OFF
"NEKTAR_USE_BLAS_LAPACK" OFF)
......@@ -171,8 +174,14 @@ ENDIF( NEKTAR_USE_MKL )
IF( NEKTAR_USE_OPENBLAS )
INCLUDE (FindOpenBlas)
SET(NEKTAR_USING_OPENBLAS TRUE)
ENDIF( NEKTAR_USE_OPENBLAS )
ENDIF( NEKTAR_USE_OPENBLAS )
IF( NEKTAR_USE_SMV )
INCLUDE (FindSMV)
SET(NEKTAR_USING_SMV TRUE)
ADD_DEFINITIONS(-DNEKTAR_USING_SMV)
ENDIF( NEKTAR_USE_SMV )
IF( NEKTAR_USE_ACCELERATE_FRAMEWORK )
INCLUDE (FindAccelerateFramework)
ENDIF( NEKTAR_USE_ACCELERATE_FRAMEWORK )
......@@ -283,7 +292,8 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/Nektar++Config.cmake
${CMAKE_SOURCE_DIR}/cmake/NektarCommon.cmake
${CMAKE_SOURCE_DIR}/cmake/FindTinyXml.cmake
${CMAKE_SOURCE_DIR}/cmake/FindGSMPI.cmake
${CMAKE_SOURCE_DIR}/cmake/FindXXT.cmake
${CMAKE_SOURCE_DIR}/cmake/FindXXT.cmake
${CMAKE_SOURCE_DIR}/cmake/FindSMV.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX})
INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR})
......
SET(SMV_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/ThirdParty/libsmv/lib
${CMAKE_SOURCE_DIR}/../ThirdParty/libsmv/lib
${CMAKE_SOURCE_DIR}/ThirdParty/dist/lib
${CMAKE_SOURCE_DIR}/../ThirdParty/dist/lib
CACHE PATH "SMV include path")
FIND_PATH(SMV_INCLUDE_DIR libsmv.h PATHS ${SMV_SEARCH_PATHS})
FIND_LIBRARY(SMV_LIBRARY NAMES smv PATHS ${SMV_SEARCH_PATHS})
SET(SMV_FOUND FALSE)
IF (SMV_LIBRARY)
SET(SMV_FOUND TRUE)
MARK_AS_ADVANCED(SMV_LIBRARY)
MARK_AS_ADVANCED(SMV_INCLUDE_DIR)
ENDIF (SMV_LIBRARY)
IF (SMV_FOUND)
IF (NOT SMV_FIND_QUIETLY)
MESSAGE(STATUS "Found SMV: ${SMV_INCLUDE_DIR}")
ENDIF (NOT SMV_FIND_QUIETLY)
ELSE(SMV_FOUND)
IF (SMV_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find SMV")
ENDIF (SMV_FIND_REQUIRED)
ENDIF (SMV_FOUND)
......@@ -32,6 +32,9 @@ SET(Boost_PROGRAM_OPTIONS_LIBRARY "@Boost_PROGRAM_OPTIONS_LIBRARY@")
SET(NEKTAR_USE_DIRECT_BLAS_CALLS "@NEKTAR_USE_DIRECT_BLAS_CALLS@")
MARK_AS_ADVANCED(NEKTAR_USE_DIRECT_BLAS_CALLS)
SET(NEKTAR_USE_SMV "@NEKTAR_USE_SMV@")
MARK_AS_ADVANCED(NEKTAR_USE_SMV)
SET(NEKTAR_USE_MPI "@NEKTAR_USE_MPI@")
SET(MPI_LIBRARY "@MPI_LIBRARY@")
SET(MPI_EXTRA_LIBRARY "@MPI_EXTRA_LIBRARY@")
......@@ -151,6 +154,10 @@ MARK_AS_ADVANCED(NEKTAR_RELEASE_LIBRARIES)
MARK_AS_ADVANCED(NEKTAR_DEBUG_LIBRARIES)
MARK_AS_ADVANCED(NEKTAR_RELEASE_WITH_DEBUG_INFO_LIBRARIES)
IF(NEKTAR_USE_SMV)
INCLUDE_DIRECTORIES(${SMV_INCLUDE_DIR})
ENDIF(NEKTAR_USE_SMV)
IF(NEKTAR_USE_FFTW)
INCLUDE_DIRECTORIES(${FFTW_INCLUDE_DIR})
ENDIF(NEKTAR_USE_FFTW)
......@@ -168,3 +175,4 @@ SET(NEKTAR_USING_LAPACK "@NEKTAR_USING_LAPACK@")
SET(NEKTAR_USING_MKL "@NEKTAR_USING_MKL@")
SET(NEKTAR_USING_ACML "@NEKTAR_USING_ACML@")
SET(NEKTAR_USING_OPENBLAS "@NEKTAR_USING_OPENBLAS@")
SET(NEKTAR_USING_SMV "@NEKTAR_USING_SMV@")
......@@ -37,6 +37,10 @@ MACRO(SET_LAPACK_LINK_LIBRARIES name)
TARGET_LINK_LIBRARIES(${name} ${NATIVE_LAPACK} ${OPENBLAS})
ENDIF( NEKTAR_USE_OPENBLAS AND OPENBLAS_FOUND )
IF( NEKTAR_USE_SMV AND SMV_FOUND )
TARGET_LINK_LIBRARIES(${name} ${SMV_LIBRARY})
ENDIF( NEKTAR_USE_SMV AND SMV_FOUND )
IF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )
TARGET_LINK_LIBRARIES(${name} ${NATIVE_LAPACK} ${NATIVE_BLAS})
ENDIF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )
......
......@@ -34,6 +34,7 @@ int main(int argc, char *argv[])
StdRegions::ConstFactorMap factors;
StdRegions::VarCoeffMap varcoeffs;
FlagList flags;
NekDouble st;
if( (argc != 2) && (argc != 3) && (argc != 4))
{
......@@ -140,7 +141,7 @@ int main(int argc, char *argv[])
Exp->HelmSolve(Fce->GetPhys(), Exp->UpdateCoeffs(), flags, factors, varcoeffs);
}
Timing("1000 Helmholtz Solves:... ");
Timing("20 Helmholtz Solves:... ");
#endif
//----------------------------------------------
......
......@@ -55,6 +55,10 @@ SET(LinearAlgebraHeaders
./LinearAlgebra/SparseUtils.hpp
)
IF(NEKTAR_USE_SMV)
SET(LinearAlgebraHeaders ${LinearAlgebraHeaders} ./LinearAlgebra/LibSMV.hpp)
ENDIF(NEKTAR_USE_SMV)
SET(FoundationHeaders
./Foundations/Graph.h
./Foundations/Basis.h
......@@ -218,6 +222,10 @@ SET(LinearAlgebraSources
./LinearAlgebra/SparseMatrix.cpp
)
IF(NEKTAR_USE_SMV)
SET(LinearAlgebraSources ${LinearAlgebraSources} ./LinearAlgebra/LibSMV.cpp)
ENDIF(NEKTAR_USE_SMV)
SET(KernelHeaders
./Kernel/kernel.h
)
......
///////////////////////////////////////////////////////////////////////////////
//
// File LibSMV.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: wrapper of functions around SMV routines
//
///////////////////////////////////////////////////////////////////////////////
#ifdef NEKTAR_USING_SMV
#include <LibUtilities/LinearAlgebra/LibSMV.hpp>
// Translations for using Fortran version of SMV
namespace Smv
{
/// \brief LibSmv matrix-vector multiply: Y = Y + A*X where A is [m x k]-matrix
template <typename T>
void Smvn (const int& m, const T* a, const T* x, T* y)
{
F77NAME(smv) (m,a,x,y);
}
/// Explicit instantiation with type double:
template LIB_UTILITIES_EXPORT void Smvn (const int& m,
const double* a, const double* x, double* y);
}
#endif
///////////////////////////////////////////////////////////////////////////////
//
// File: LibSMV.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: wrapper of functions around SMV routines
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SMV_HPP
#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SMV_HPP
#ifdef NEKTAR_USING_SMV
#include <LibUtilities/LinearAlgebra/TransF77.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <boost/preprocessor/iteration/local.hpp>
#define LIBSMV_MAX_RANK 12
namespace Smv
{
// Translations for using Fortran version of SMV
extern "C"
{
/// \brief Matrix-vector multiply C = C + A*B where
/// A is [m x m], B is [m] and C is [m].
/// Expected: no matrix transpose, row-major ordering,
/// unit increments and no matrix views (lda != m|n|k),
/// type double, no constant factors.
void F77NAME(smv) (
const int& m,
const double* a, const double* b, double* c);
/// \brief Rank-specific matrix-vector LibSMV multiply
/// kernels. Row-major ordering, unit increments,
/// type double. May eventually call dgemv
/// implementation that LibSMV is linked against.
#define BOOST_PP_LOCAL_MACRO(n) \
void F77NAME(smv_##n) \
(const double* a, \
const double* b, \
double* c);
#define BOOST_PP_LOCAL_LIMITS (1, LIBSMV_MAX_RANK)
#include BOOST_PP_LOCAL_ITERATE()
}
/// \brief LibSmv matrix-vector multiply: Y = Y + A*X where A is [m x m]-matrix
template <typename T>
LIB_UTILITIES_EXPORT void Smvn (const int& m,
const T* a, const T* x, T* y);
}
#endif // NEKTAR_USING_SMV
#endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SMV_HPP
......@@ -47,6 +47,9 @@
#include <LibUtilities/LinearAlgebra/StorageBsrUnrolled.hpp>
#include <LibUtilities/LinearAlgebra/NistSparseDescriptors.hpp>
#include <LibUtilities/LinearAlgebra/LibSMV.hpp>
#include <boost/preprocessor/iteration/local.hpp>
#include <boost/lexical_cast.hpp>
namespace Nektar
......@@ -242,6 +245,17 @@ namespace Nektar
throw 1;
}
#ifdef NEKTAR_USING_SMV
// Set pointer to rank-specific matrix-vector multiply kernel.
// Number of ranks is defined by LibSMV library
switch (blkDim)
{
#define BOOST_PP_LOCAL_MACRO(n) case n: m_mvKernel = Smv::F77NAME(smv_##n); break;
#define BOOST_PP_LOCAL_LIMITS (1, LIBSMV_MAX_RANK)
#include BOOST_PP_LOCAL_ITERATE()
}
#endif
processBcoInput(blkRows,blkCols,blkDim,bcoMat);
}
......@@ -376,6 +390,9 @@ namespace Nektar
const int mb = m_blkRows;
const int kb = m_blkCols;
#ifdef NEKTAR_USING_SMV
Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c);
#else
switch(m_blkDim)
{
case 2: Multiply_2x2(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
......@@ -383,6 +400,7 @@ namespace Nektar
case 4: Multiply_4x4(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
default: Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
}
#endif
}
......@@ -400,6 +418,9 @@ namespace Nektar
const int mb = m_blkRows;
const int kb = m_blkCols;
#ifdef NEKTAR_USING_SMV
Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c);
#else
switch(m_blkDim)
{
case 2: Multiply_2x2(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
......@@ -407,6 +428,7 @@ namespace Nektar
case 4: Multiply_4x4(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
default: Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
}
#endif
}
......@@ -426,6 +448,9 @@ namespace Nektar
const int mb = m_blkRows;
const int kb = m_blkCols;
#ifdef NEKTAR_USING_SMV
Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c);
#else
switch(m_blkDim)
{
case 2: Multiply_2x2(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
......@@ -433,6 +458,7 @@ namespace Nektar
case 4: Multiply_4x4(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
default: Multiply_generic(mb,kb,val,bindx,bpntrb,bpntre,b,c); return;
}
#endif
}
/// Zero-based BSR multiply unrolled for 2x2 blocks.
......@@ -598,6 +624,10 @@ namespace Nektar
bs=bindx[j]*lb;
pb = &b[bs];
#ifdef NEKTAR_USING_SMV
m_mvKernel(pval,pb,pc);
pval+=mm;
#else
for (jj=0;jj!=lb;jj++)
{
const double t = pb[jj];
......@@ -606,6 +636,7 @@ namespace Nektar
pc[ii] += t* (*pval++);
}
}
#endif
}
pc += lb;
}
......
......@@ -67,6 +67,8 @@ namespace Nektar
typedef Array<OneD, const DataType> ConstDataVectorType;
typedef Array<OneD, IndexType> IndexVectorType;
typedef void (*MultiplyKernel)(const double*, const double*, double*);
/// \internal
/// \brief Forward iterator through nonzero (double) elements of the matrix
/// that mimics forward iteration of BCOMatType.
......@@ -182,6 +184,9 @@ namespace Nektar
const double* b, double* c);
// interface to lowest level LibSMV multiply kernels
MultiplyKernel m_mvKernel;
MatrixStorage m_matType;
IndexType m_blkRows; // number of block rows
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment