Skip to content
Snippets Groups Projects
Commit db4d905d authored by Spencer Sherwin's avatar Spencer Sherwin
Browse files

Use BOOST_PP to generate switch statement in MatrixFreeOps to allow ability to secify range

parent d4a32a6a
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,9 @@ Changelog ...@@ -2,8 +2,9 @@ Changelog
========= =========
v5.7.0 v5.7.0
------ -----
**Library** **Library**
- Modified MatrixFreeOp library switch initialisation to use BOOST_PP (!1794)
- Fix memory-leak with LowEnergyBlock preconditioner for time-updated matrices (!1627) - Fix memory-leak with LowEnergyBlock preconditioner for time-updated matrices (!1627)
- Fix Fourier expansion integration weights are related test (!1803) - Fix Fourier expansion integration weights are related test (!1803)
......
...@@ -220,6 +220,13 @@ IF (${CMAKE_COMPILER_IS_GNUCXX}) ...@@ -220,6 +220,13 @@ IF (${CMAKE_COMPILER_IS_GNUCXX})
MARK_AS_ADVANCED(NEKTAR_ENABLE_PROFILE) MARK_AS_ADVANCED(NEKTAR_ENABLE_PROFILE)
ENDIF (${CMAKE_COMPILER_IS_GNUCXX}) ENDIF (${CMAKE_COMPILER_IS_GNUCXX})
# Automatic Switch generation range
SET(NEKTAR_SWITCH_MIN 2 CACHE STRING "Set min range of auto generated switch")
MARK_AS_ADVANCED(NEKTAR_SWITCH_MIN)
SET(NEKTAR_SWITCH_MAX 8 CACHE STRING "Set max range of auto generated switch")
MARK_AS_ADVANCED(NEKTAR_SWITCH_MAX)
# Memory pools # Memory pools
OPTION(NEKTAR_USE_MEMORY_POOLS OPTION(NEKTAR_USE_MEMORY_POOLS
"Use memory pools to accelerate memory allocation." ON) "Use memory pools to accelerate memory allocation." ON)
......
...@@ -6,6 +6,11 @@ SET(MATRIXFREEOPS_SOURCES ...@@ -6,6 +6,11 @@ SET(MATRIXFREEOPS_SOURCES
Operator.cpp Operator.cpp
) )
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/SwitchLimits.h.in
${CMAKE_CURRENT_SOURCE_DIR}/SwitchLimits.h
@ONLY)
# Boilerplate cpp implementation files for registering an operator # Boilerplate cpp implementation files for registering an operator
# with the factory. There are individual files for each operator shape # with the factory. There are individual files for each operator shape
# so to reduce compile time timeout failures due to the large number # so to reduce compile time timeout failures due to the large number
......
///////////////////////////////////////////////////////////////////////////////
//
// File: SwitchLimits.h
//
// 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).
//
// 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: Set the wwitch limits
//
///////////////////////////////////////////////////////////////////////////////
#define MIN1D @NEKTAR_SWITCH_MIN@
#define MAX1D @NEKTAR_SWITCH_MAX@
#define MIN2D @NEKTAR_SWITCH_MIN@
#define MAX2D @NEKTAR_SWITCH_MAX@
#define MIN3D @NEKTAR_SWITCH_MIN@
#define MAX3D @NEKTAR_SWITCH_MAX@
This diff is collapsed.
...@@ -41,52 +41,77 @@ ...@@ -41,52 +41,77 @@
// but becasue the operator{1,23}D is both a function and template that // but becasue the operator{1,23}D is both a function and template that
// need to be in the inherited class it is not possible. // need to be in the inherited class it is not possible.
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/comparison/not_equal.hpp>
#include <boost/preprocessor/repetition/for.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include "SwitchLimits.h"
/* Macro compares the values of the tuple 'state' to see if the first
element, given by BOOST_PP_TUPLE_ELEM(2, 0, state), is not equal to
the second element plus one, given by
BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 1, state)) and returns 1 if not
equal otherwise zero */
#define TEST(r, state) \
BOOST_PP_NOT_EQUAL(BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 1, state)))
/* Macro returns a tuple where the first element, given by
BOOST_PP_TUPLE_ELEM(2, 0, state), is incremented by one and the
second element, given by BOOST_PP_TUPLE_ELEM(2, 1, state) remains
the same*/
#define UPDATE(r, state) \
(BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
BOOST_PP_TUPLE_ELEM(2, 1, state))
#if defined(SHAPE_DIMENSION_1D) #if defined(SHAPE_DIMENSION_1D)
/* Define the switch statement for 1D shape operators and min, max range */
#define OPERATOR1D(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator1D<BOOST_PP_TUPLE_ELEM(2, 0, state)>(input, output); \
break;
/* start of switch include for operator1D */
{ {
const int nq0 = m_basis[0]->GetNumPoints(); const int nq0 = m_basis[0]->GetNumPoints();
#if defined(SHAPE_TYPE_SEG) #if defined(SHAPE_TYPE_SEG)
switch (nq0) switch (nq0)
{ {
case 2: /*
operator1D<2>(input, output); expand OPERATOR1D case from 2 to 10, i.e.
break; ..
case 3: case 4:
operator1D<3>(input, output); operator1D<4>(input,output);
break; break;
case 4: ...
operator1D<4>(input, output); */
break; BOOST_PP_FOR((MIN1D, MAX1D), TEST, UPDATE, OPERATOR1D)
case 5:
operator1D<5>(input, output);
break;
case 6:
operator1D<6>(input, output);
break;
case 7:
operator1D<7>(input, output);
break;
case 8:
operator1D<8>(input, output);
break;
case 9:
operator1D<9>(input, output);
break;
case 10:
operator1D<10>(input, output);
break;
default: default:
operator1D(input, output); operator1D(input, output);
break; break;
} }
#endif #endif
} }
#elif defined(SHAPE_DIMENSION_2D) #elif defined(SHAPE_DIMENSION_2D)
/* Define the switch statement for 2D shape operators and min, max range */
#define OPERATOR2D_TRI(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator2D<BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2, 0, state))>(input, \
output); \
break;
#define OPERATOR2D_QUAD(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator2D<BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_TUPLE_ELEM(2, 0, state)>(input, output); \
break;
/* start of switch include for operator2D */
{ {
const int nq0 = m_basis[0]->GetNumPoints(); const int nq0 = m_basis[0]->GetNumPoints();
const int nq1 = m_basis[1]->GetNumPoints(); const int nq1 = m_basis[1]->GetNumPoints();
...@@ -97,33 +122,16 @@ ...@@ -97,33 +122,16 @@
{ {
switch (m_basis[0]->GetNumPoints()) switch (m_basis[0]->GetNumPoints())
{ {
case 2: /*
operator2D<2, 1>(input, output); expand OPERATOR2D case from 2 to 10, i.e.
break; ..
case 3: case 4:
operator2D<3, 2>(input, output); operator2D<4,3>(input,output);
break; break;
case 4: ...
operator2D<4, 3>(input, output); */
break; BOOST_PP_FOR((MIN2D, MAX2D), TEST, UPDATE, OPERATOR2D_TRI);
case 5:
operator2D<5, 4>(input, output);
break;
case 6:
operator2D<6, 5>(input, output);
break;
case 7:
operator2D<7, 6>(input, output);
break;
case 8:
operator2D<8, 7>(input, output);
break;
case 9:
operator2D<9, 8>(input, output);
break;
case 10:
operator2D<10, 9>(input, output);
break;
default: default:
operator2D(input, output); operator2D(input, output);
break; break;
...@@ -136,33 +144,15 @@ ...@@ -136,33 +144,15 @@
{ {
switch (m_basis[0]->GetNumPoints()) switch (m_basis[0]->GetNumPoints())
{ {
case 2: /*
operator2D<2, 2>(input, output); expand OPERATOR2D case from 2 to 10, i.e.
break; ..
case 3: case 4:
operator2D<3, 3>(input, output); operator2D<4,4>(input,output);
break; break;
case 4: ...
operator2D<4, 4>(input, output); */
break; BOOST_PP_FOR((MIN2D, MAX2D), TEST, UPDATE, OPERATOR2D_QUAD)
case 5:
operator2D<5, 5>(input, output);
break;
case 6:
operator2D<6, 6>(input, output);
break;
case 7:
operator2D<7, 7>(input, output);
break;
case 8:
operator2D<8, 8>(input, output);
break;
case 9:
operator2D<9, 9>(input, output);
break;
case 10:
operator2D<10, 10>(input, output);
break;
default: default:
operator2D(input, output); operator2D(input, output);
break; break;
...@@ -179,6 +169,31 @@ ...@@ -179,6 +169,31 @@
#elif defined(SHAPE_DIMENSION_3D) #elif defined(SHAPE_DIMENSION_3D)
/* Define the switch statement for 3D shape operators and min, max range */
#define OPERATOR3D_HEX(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator3D<BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_TUPLE_ELEM(2, 0, state)>(input, output); \
break;
#define OPERATOR3D_TET(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator3D<BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2, 0, state))>(input, \
output); \
break;
#define OPERATOR3D_PYR_PRISM(r, state) \
case BOOST_PP_TUPLE_ELEM(2, 0, state): \
operator3D<BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_TUPLE_ELEM(2, 0, state), \
BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2, 0, state))>(input, \
output); \
break;
/* start of include switch details for operator3D */
{ {
const int nq0 = m_basis[0]->GetNumPoints(); const int nq0 = m_basis[0]->GetNumPoints();
const int nq1 = m_basis[1]->GetNumPoints(); const int nq1 = m_basis[1]->GetNumPoints();
...@@ -190,51 +205,16 @@ ...@@ -190,51 +205,16 @@
{ {
switch (m_basis[0]->GetNumPoints()) switch (m_basis[0]->GetNumPoints())
{ {
case 2: /*
operator3D<2, 2, 2>(input, output); expand OPERATOR3D case from 2 to 16, i.e.
break; ..
case 3: case 4:
operator3D<3, 3, 3>(input, output); operator3D<4,4,4>(input,output);
break; break;
case 4: ...
operator3D<4, 4, 4>(input, output); */
break; BOOST_PP_FOR((MIN3D, MAX3D), TEST, UPDATE, OPERATOR3D_HEX)
case 5:
operator3D<5, 5, 5>(input, output);
break;
case 6:
operator3D<6, 6, 6>(input, output);
break;
case 7:
operator3D<7, 7, 7>(input, output);
break;
case 8:
operator3D<8, 8, 8>(input, output);
break;
case 9:
operator3D<9, 9, 9>(input, output);
break;
case 10:
operator3D<10, 10, 10>(input, output);
break;
case 11:
operator3D<11, 11, 11>(input, output);
break;
case 12:
operator3D<12, 12, 12>(input, output);
break;
case 13:
operator3D<13, 13, 13>(input, output);
break;
case 14:
operator3D<14, 14, 14>(input, output);
break;
case 15:
operator3D<15, 15, 15>(input, output);
break;
case 16:
operator3D<16, 16, 16>(input, output);
break;
default: default:
operator3D(input, output); operator3D(input, output);
break; break;
...@@ -247,48 +227,15 @@ ...@@ -247,48 +227,15 @@
{ {
switch (nq0) switch (nq0)
{ {
case 3: /*
operator3D<3, 2, 2>(input, output); expand OPERATOR3D case from 2 to 16, i.e.
break; ..
case 4: case 4:
operator3D<4, 3, 3>(input, output); operator3D<4,3,3>(input,output);
break; break;
case 5: ...
operator3D<5, 4, 4>(input, output); */
break; BOOST_PP_FOR((MIN3D, MAX3D), TEST, UPDATE, OPERATOR3D_TET)
case 6:
operator3D<6, 5, 5>(input, output);
break;
case 7:
operator3D<7, 6, 6>(input, output);
break;
case 8:
operator3D<8, 7, 7>(input, output);
break;
case 9:
operator3D<9, 8, 8>(input, output);
break;
case 10:
operator3D<10, 9, 9>(input, output);
break;
case 11:
operator3D<11, 10, 10>(input, output);
break;
case 12:
operator3D<12, 11, 11>(input, output);
break;
case 13:
operator3D<13, 12, 12>(input, output);
break;
case 14:
operator3D<14, 13, 13>(input, output);
break;
case 15:
operator3D<15, 14, 14>(input, output);
break;
case 16:
operator3D<16, 15, 15>(input, output);
break;
default: default:
operator3D(input, output); operator3D(input, output);
break; break;
...@@ -301,51 +248,15 @@ ...@@ -301,51 +248,15 @@
{ {
switch (m_basis[0]->GetNumPoints()) switch (m_basis[0]->GetNumPoints())
{ {
case 2: /*
operator3D<2, 2, 1>(input, output); expand OPERATOR3D case from 3 to 16, i.e.
break; ..
case 3: case 4:
operator3D<3, 3, 2>(input, output); operator3D<4,3,3>(input,output);
break; break;
case 4: ...
operator3D<4, 4, 3>(input, output); */
break; BOOST_PP_FOR((MIN3D, MAX3D), TEST, UPDATE, OPERATOR3D_PYR_PRISM)
case 5:
operator3D<5, 5, 4>(input, output);
break;
case 6:
operator3D<6, 6, 5>(input, output);
break;
case 7:
operator3D<7, 7, 6>(input, output);
break;
case 8:
operator3D<8, 8, 7>(input, output);
break;
case 9:
operator3D<9, 9, 8>(input, output);
break;
case 10:
operator3D<10, 10, 9>(input, output);
break;
case 11:
operator3D<11, 11, 10>(input, output);
break;
case 12:
operator3D<12, 12, 11>(input, output);
break;
case 13:
operator3D<13, 13, 12>(input, output);
break;
case 14:
operator3D<14, 14, 13>(input, output);
break;
case 15:
operator3D<15, 15, 14>(input, output);
break;
case 16:
operator3D<16, 16, 15>(input, output);
break;
default: default:
operator3D(input, output); operator3D(input, output);
break; break;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<value variable="E" tolerance="1e-12">3.03058e-05</value> <value variable="E" tolerance="1e-12">3.03058e-05</value>
</metric> </metric>
<metric type="ExecutionTime" id="3"> <metric type="ExecutionTime" id="3">
<value tolerance="1e0" hostname="42.debian-bullseye-performance-build-and-test">36.0</value> <value tolerance="1e0" hostname="42.debian-bullseye-performance-build-and-test">34.0</value>
</metric> </metric>
</metrics> </metrics>
</test> </test>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<value variable="p" tolerance="1e-7">0.0671074</value> <value variable="p" tolerance="1e-7">0.0671074</value>
</metric> </metric>
<metric type="ExecutionTime" id="3"> <metric type="ExecutionTime" id="3">
<value tolerance="8e-1" hostname="42.debian-bullseye-performance-build-and-test">13.758</value> <value tolerance="8e-1" hostname="42.debian-bullseye-performance-build-and-test">13.3</value>
</metric> </metric>
</metrics> </metrics>
</test> </test>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<value variable="u" tolerance="1e-12">6.05588</value> <value variable="u" tolerance="1e-12">6.05588</value>
</metric> </metric>
<metric type="ExecutionTime" id="3"> <metric type="ExecutionTime" id="3">
<value tolerance="3e-1" hostname="42.debian-bullseye-performance-build-and-test">6.05743</value> <value tolerance="6e-1" hostname="42.debian-bullseye-performance-build-and-test">6.05743</value>
</metric> </metric>
</metrics> </metrics>
</test> </test>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment