geo-fluid-dynamics / phaseflow-dealii

Phaseflow simulates the convection-coupled melting and solidification of phase-change materials.
https://geo-fluid-dynamics.github.io/phaseflow-dealii
MIT License
3 stars 0 forks source link

Can't resize std::vector<Functions::ParsedFunction<dim>> #10

Closed agzimmerman closed 7 years ago

agzimmerman commented 7 years ago

Attempting to resize or push_back into a std::vector<Functions::ParsedFunction> throws an error within TBB and/or mu::Parser, e.g.:

In file included from /usr/include/c++/4.8/vector:64:0, from /usr/include/c++/4.8/bits/random.h:34, from /usr/include/c++/4.8/random:50, from /usr/include/c++/4.8/bits/stl_algo.h:65, from /usr/include/c++/4.8/algorithm:62, from /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/bundled/tbb/concurrent_vector.h:48, from /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/bundled/tbb/enumerable_thread_specific.h:32, from /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/base/thread_local_storage.h:23, from /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/base/logstream.h:23, from /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/lac/vector.h:21, from /mnt/c/Users/Alex/UbuntuShared/nsb-pcm/tests/peclet_data.cc:1: /usr/include/c++/4.8/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = mu::Parser; _Alloc = std::allocator]’: /usr/include/c++/4.8/bits/stl_vector.h:416:33: required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = mu::Parser; _Alloc = std::allocator]’ /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/bundled/tbb/enumerable_thread_specific.h:659:17: required from ‘void tbb::interface6::internal::ets_element<U, ModularSize>::unconstruct() [with U = std::vector; long unsigned int ModularSize = 24ul]’ /home/zimmerman/installed/deal.ii-candi/deal.II-v8.4.2/include/deal.II/bundled/tbb/enumerable_thread_specific.h:729:17: required from ‘void tbb::interface6::enumerable_thread_specific<T, Allocator, ETS_key_type>::unconstruct_locals() [with T = std::vector; Allocator = tbb::cache_aligned_allocator<std::vector >; tbb::ets_key_usage_type ETS_key_type = (tbb::ets_key_usage_type)1u]’

Because of this issue, the number of boundaries on the domain must be known at compile time (i.e. they can't be set in the input parameter file), so that the proper number of ParsedFunction objects can be allocated.

Maybe ParsedFunction does not mean these requirements: http://stackoverflow.com/questions/12251368/type-requirements-for-stdvectortype

How are other deal.II users solving this problem?

I'm going to create a test for this bug/issue number now.

agzimmerman commented 7 years ago

Here's the test: https://github.com/alexanderzimmerman/nsb-pcm/blob/bugs/tests/bug_10_fail.cc

agzimmerman commented 7 years ago

I'm seeking help on the deal.II mailing list: https://groups.google.com/forum/#!topic/dealii/kToGg5lNhFE

agzimmerman commented 7 years ago

Per Luca's suggestion, I'm trying to accomplish this with a std::shared_ptr. See commit 91a755b1c32351f729b9ad811b56c5c72bfa48e2

Now resizing and declaring works, but parse_parameters seg faults:

$ gdb bug_10_fail.debug
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from bug_10_fail.debug...done.
(gdb) run
Starting program: /home/zimmerman/build/nsb-pcm/tests/bug_10_fail.debug/bug_10_fail.debug
warning: Error disabling address space randomization: Success
warning: linux_ptrace_test_ret_to_nx: PTRACE_KILL waitpid returned -1: Interrupted system call
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7f53c0850700 (LWP 9572)]
[New Thread 0x7f53c0040700 (LWP 9573)]
[New Thread 0x7f53bd830700 (LWP 9574)]

Program received signal SIGSEGV, Segmentation fault.
unconstruct_locals (this=0x148)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/bundled/tbb41_20130401oss/include/tbb/enumerable_thread_specific.h:728
728                 for(typename internal_collection_type::iterator cvi = my_locals.begin(); cvi != my_locals.end(); ++cvi) {
(gdb) up
#1  clear (this=0x148)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/bundled/tbb41_20130401oss/include/tbb/enumerable_thread_specific.h:826
826                 unconstruct_locals();
(gdb) up
#2  clear (this=0x148)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/include/deal.II/base/thread_local_storage.h:269
269         data.clear ();
(gdb) up
#3  dealii::FunctionParser<2>::initialize (this=this@entry=0x88, variables="x,y,t",
Python Exception <class 'IndexError'> list index out of range:
    expressions=std::vector of length 1, capacity 1 = {...}, constants=std::map with 2 elements,
    time_dependent=time_dependent@entry=true)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/source/base/function_parser.cc:68
68        this->fp.clear(); // this will reset all thread-local objects
(gdb) up
#4  0x00007f53dbd00c00 in dealii::FunctionParser<2>::initialize (this=this@entry=0x88, vars="x,y,t",
Python Exception <class 'IndexError'> list index out of range:
    expression="0", constants=std::map with 2 elements, time_dependent=time_dependent@entry=true)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/source/base/function_parser.cc:361
361       initialize(vars, Utilities::split_string_list(expression, ';'),
(gdb) up
#5  0x00007f53dbd459d2 in dealii::Functions::ParsedFunction<2>::parse_parameters (this=0x0, prm=...)
    at /home/zimmerman/installed/deal.ii-candi/tmp/unpack/deal.II-v8.4.2/source/base/parsed_function.cc:139
139             function_object.initialize(vnames, expression, constants, true);
(gdb) up
#6  0x0000000000409f23 in main () at /mnt/c/Users/Alex/UbuntuShared/nsb-pcm/tests/bug_10_fail.cc:42
42                  function_pointers[f]->parse_parameters(prm);
(gdb)
agzimmerman commented 7 years ago

I verified that the test passes if I use a std::vector<dealii::Functions::ParsedFunction> without resizing: https://github.com/alexanderzimmerman/nsb-pcm/blob/bugs/tests/bug_10_pass.cc

agzimmerman commented 7 years ago

Resize still doesn't work; but push_back is working as of commit 1ff39170818da6ea57182b15b8cc7cd1decbeddf . See https://github.com/alexanderzimmerman/nsb-pcm/blob/bugs/tests/issue_10_push_back.cc for details.

push_back suffices, so this issue is resolved.

agzimmerman commented 7 years ago

And now resize works as of commit 577387099ce1bd104180679d9e8e0bb86a6d3773