From 5972e85ffea25cb5e60790eba9a9571719052131 Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 26 Sep 2003 15:01:29 +0000 Subject: [PATCH] Detect the minimal capacity of vectors. Use it. git-svn-id: https://svn.dealii.org/trunk@8036 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/aclocal.m4 | 64 +++++++++ deal.II/base/include/base/config.h.in | 8 ++ deal.II/configure | 135 ++++++++++++++++++ deal.II/configure.in | 1 + .../source/grid/tria.all_dimensions.cc | 45 +++--- 5 files changed, 236 insertions(+), 17 deletions(-) diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index 8c8ee69057..50570ef1bb 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -2824,6 +2824,9 @@ static preload_terminate_dummy dummy; + + + dnl ------------------------------------------------------------- dnl gcc versions up to 2.95.3 had a problem with the std::advance function, dnl when the number of steps forward was given by an unsigned number, since @@ -2866,6 +2869,67 @@ AC_DEFUN(DEAL_II_CHECK_ADVANCE_WARNING, dnl +dnl ------------------------------------------------------------- +dnl +dnl Usage: DEAL_II_CHECK_MIN_VECTOR_CAPACITY +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_MIN_VECTOR_CAPACITY, dnl +[ + AC_LANG(C++) + CXXFLAGS="$CXXFLAGSG -Werror" + + AC_MSG_CHECKING(for minimal std::vector capacity) + AC_TRY_RUN( + [ +#include +int main () { + std::vector v(1); + v.reserve (1); + v.resize (1); + return v.capacity(); +} + ], + [ + dnl That's impossible: the return value can't be zero! + AC_MSG_ERROR(impossible result -- aborting) + ], + [ + result="$?" + AC_MSG_RESULT($result) + AC_DEFINE_UNQUOTED(DEAL_II_MIN_VECTOR_CAPACITY, $result, + [Set to the minimal number of elements a std::vector can + always hold, i.e. its minimal capacity.]) + ] + ) + + dnl Do same thing with std::vector + AC_MSG_CHECKING(for minimal std::vector capacity) + AC_TRY_RUN( + [ +#include +int main () { + std::vector v(1); + v.reserve (1); + v.resize (1); + return v.capacity(); +} + ], + [ + dnl That's impossible: the return value can't be zero! + AC_MSG_ERROR(impossible result -- aborting) + ], + [ + result="$?" + AC_MSG_RESULT($result) + AC_DEFINE_UNQUOTED(DEAL_II_MIN_BOOL_VECTOR_CAPACITY, $result, + [Set to the minimal number of elements a std::vector can + always hold, i.e. its minimal capacity.]) + ] + ) +]) + + + dnl ------------------------------------------------------------- dnl Check whether the numeric_limits classes are available dnl diff --git a/deal.II/base/include/base/config.h.in b/deal.II/base/include/base/config.h.in index 32d66a866d..86146093d1 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -80,6 +80,14 @@ /* Minor version number of deal.II */ #undef DEAL_II_MINOR +/* Set to the minimal number of elements a std::vector can always hold, + i.e. its minimal capacity. */ +#undef DEAL_II_MIN_BOOL_VECTOR_CAPACITY + +/* Set to the minimal number of elements a std::vector can always hold, + i.e. its minimal capacity. */ +#undef DEAL_II_MIN_VECTOR_CAPACITY + /* Define if we have to work around a bug in gcc with marking all instances of a template class as friends to this class if the class is inside a namespace. See the aclocal.m4 file in the top-level directory for a diff --git a/deal.II/configure b/deal.II/configure index 961722b610..fe70fafefb 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -5727,6 +5727,141 @@ fi rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + ac_ext=cc +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + CXXFLAGS="$CXXFLAGSG -Werror" + + echo "$as_me:$LINENO: checking for minimal std::vector capacity" >&5 +echo $ECHO_N "checking for minimal std::vector capacity... $ECHO_C" >&6 + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +int main () { + std::vector v(1); + v.reserve (1); + v.resize (1); + return v.capacity(); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { { echo "$as_me:$LINENO: error: impossible result -- aborting" >&5 +echo "$as_me: error: impossible result -- aborting" >&2;} + { (exit 1); exit 1; }; } + +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + + result="$?" + echo "$as_me:$LINENO: result: $result" >&5 +echo "${ECHO_T}$result" >&6 + +cat >>confdefs.h <<_ACEOF +#define DEAL_II_MIN_VECTOR_CAPACITY $result +_ACEOF + + + +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: checking for minimal std::vector capacity" >&5 +echo $ECHO_N "checking for minimal std::vector capacity... $ECHO_C" >&6 + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +int main () { + std::vector v(1); + v.reserve (1); + v.resize (1); + return v.capacity(); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { { echo "$as_me:$LINENO: error: impossible result -- aborting" >&5 +echo "$as_me: error: impossible result -- aborting" >&2;} + { (exit 1); exit 1; }; } + +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + + result="$?" + echo "$as_me:$LINENO: result: $result" >&5 +echo "${ECHO_T}$result" >&6 + +cat >>confdefs.h <<_ACEOF +#define DEAL_II_MIN_BOOL_VECTOR_CAPACITY $result +_ACEOF + + + +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: checking whether getrusage is properly declared" >&5 echo $ECHO_N "checking whether getrusage is properly declared... $ECHO_C" >&6 ac_ext=cc diff --git a/deal.II/configure.in b/deal.II/configure.in index 0dfc4d10d7..51402e25de 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -188,6 +188,7 @@ DEAL_II_HAVE_STD_OSTREAM_HEADER DEAL_II_HAVE_STD_IOSFWD_HEADER DEAL_II_HAVE_BUILTIN_EXPECT DEAL_II_HAVE_VERBOSE_TERMINATE +DEAL_II_CHECK_MIN_VECTOR_CAPACITY DEAL_II_CHECK_GETRUSAGE DEAL_II_CHECK_ISNAN DEAL_II_CHECK_RAND_R diff --git a/deal.II/deal.II/source/grid/tria.all_dimensions.cc b/deal.II/deal.II/source/grid/tria.all_dimensions.cc index c3012b6dda..b3f53e477c 100644 --- a/deal.II/deal.II/source/grid/tria.all_dimensions.cc +++ b/deal.II/deal.II/source/grid/tria.all_dimensions.cc @@ -179,19 +179,19 @@ TriangulationLevel<0>::monitor_memory (const unsigned int true_dimension) const // as many elements as an integer // has bits Assert (refine_flags.size() <= refine_flags.capacity() + sizeof(int)*8 || - refine_flags.size()<256, + refine_flags.size()::monitor_memory (const unsigned int true_dimension) const // as many elements as an integer // has bits Assert (lines.lines.size() == lines.lines.capacity() || - lines.lines.size()<256, + lines.lines.size()::monitor_memory (const unsigned int true_dimension) const // as many elements as an integer // has bits Assert (quads.quads.size() == quads.quads.capacity() || - quads.quads.size()<256, + quads.quads.size()::reserve_space (const unsigned int new_hexes) hexes.user_pointers.reserve (new_size); hexes.user_pointers.insert (hexes.user_pointers.end(), new_size-hexes.user_pointers.size(), 0); + + hexes.face_orientations.reserve (new_size * GeometryInfo<3>::faces_per_cell); + hexes.face_orientations.insert (hexes.face_orientations.end(), + new_size * GeometryInfo<3>::faces_per_cell + - hexes.face_orientations.size(), + true); }; } @@ -450,19 +456,19 @@ TriangulationLevel<3>::monitor_memory (const unsigned int true_dimension) const // as many elements as an integer // has bits Assert (hexes.hexes.size() == hexes.hexes.capacity() || - hexes.hexes.size()<256, + hexes.hexes.size()::monitor_memory (const unsigned int true_dimension) const ExcMemoryInexact (hexes.hexes.size(), hexes.material_id.size())); Assert (hexes.hexes.size() == hexes.user_pointers.size(), ExcMemoryInexact (hexes.hexes.size(), hexes.user_pointers.size())); + Assert (hexes.hexes.size() * GeometryInfo<3>::faces_per_cell + == hexes.face_orientations.size(), + ExcMemoryInexact (hexes.hexes.size() * GeometryInfo<3>::faces_per_cell, + hexes.face_orientations.size())); TriangulationLevel<2>::monitor_memory (true_dimension); } @@ -490,7 +500,8 @@ TriangulationLevel<3>::memory_consumption () const MemoryConsumption::memory_consumption (hexes.used) + MemoryConsumption::memory_consumption (hexes.user_flags) + MemoryConsumption::memory_consumption (hexes.material_id) + - MemoryConsumption::memory_consumption (hexes.user_pointers)); + MemoryConsumption::memory_consumption (hexes.user_pointers) + + MemoryConsumption::memory_consumption (hexes.face_orientations)); } -- 2.39.5