agency-library / agency

Execution primitives for C++
http://agency-library.github.io
BSD 3-Clause "New" or "Revised" License
154 stars 27 forks source link

Interval() doesn't work with tile_evenly() #334

Open alobb opened 7 years ago

alobb commented 7 years ago

Meta:

33 % g++ --version
g++ (Gentoo 4.9.4 p1.0, pie-0.6.4) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

37 % git --no-pager log -1
commit 397e0127f92837509c9f4f2f60152ab584f24346
Merge: e24a0ca 09a88f0
Author: Jared Hoberock <jaredhoberock@gmail.com>
Date:   Mon Jan 16 18:13:23 2017 -0600

    Merge pull request #332 from jaredhoberock/issue-297

    Issue 297

40 % git --no-pager diff
diff --git a/examples/hello_world.cpp b/examples/hello_world.cpp
index 9ba7b11..d42bcd9 100644
--- a/examples/hello_world.cpp
+++ b/examples/hello_world.cpp
@@ -1,15 +1,10 @@
-#include <agency/agency.hpp>
-#include <iostream>
-
-void hello(agency::sequenced_agent& self)
-{
-  std::cout << "Hello, world from agent " << self.index() << std::endl;
-}
+#include <agency/experimental.hpp>

 int main()
 {
-  // create 10 sequenced_agents to execute the hello() task in bulk
-  agency::bulk_invoke(agency::seq(10), hello);
+
+  auto intervals = agency::experimental::interval(0,10);
+  auto tiles = agency::experimental::tile_evenly(intervals, 2);

   return 0;
 }

When trying to create tiled intervals like in the following code, Agency gives errors for failed template substitutions:

#include <agency/experimental.hpp>

int main()
{

  auto intervals = agency::experimental::interval(0,10);
  auto tiles = agency::experimental::tile_evenly(intervals, 2);

  return 0;
}

The command to compile this was:

g++ -std=c++11 -I. -I agency/ examples/hello_world.cpp -o hello_world 2> error.txt

error.txt

alobb commented 7 years ago

Some things I have tried to fix this:

Added the following line to iota_view

using value_type = typename std::iterator_traits<iterator>::value_type;

Added the following function to counting_iterator

__AGENCY_ANNOTATION
difference_type operator-(counting_iterator it) const
{
    return (operator*()) - (*it);
}

These have reduced the number of errors, but I haven't figured out the errors from trying to create a span within the nested function calls.

alobb commented 7 years ago

Looking more closely at the span class (and being very unfamiliar with the code, so take this with a grain of salt), I don't see a clear way to create a span from the interval; it looks like span holds a pointer to the data, but the interval doesn't actually point to any data, since it is just a begin and end integer.

jaredhoberock commented 7 years ago

Thanks for the report and reproducer program. I can reproduce the problem on my system.

I've run into this problem before. I think the root of the problem is issue #305.

The basic problem is the way all() is called. I'm testing a fix now that seems to compile OK.

jaredhoberock commented 7 years ago

The master branch should compile your reproducer program now:

$ cat test.cpp 
#include <agency/experimental.hpp>

int main()
{

  auto intervals = agency::experimental::interval(0,10);
  auto tiles = agency::experimental::tile_evenly(intervals, 2);

  return 0;
}

$ g++ -I. -std=c++11 test.cpp 
$ ./a.out 

Please let me know if this solves the problem with your original program.

alobb commented 7 years ago

That did get the minified example to compile, thanks! Unfortunately, I have a new minified example that fails.

#include <agency/agency.hpp>
#include <agency/experimental.hpp>

int main()
{
  return 0;
}

Meta:

84 % git --no-pager log -1
commit 66436cd211824fe40eb9629741e944fd36df742b
Merge: 397e012 076239a
Author: Jared Hoberock <jaredhoberock@gmail.com>
Date:   Mon Jan 23 18:24:40 2017 -0600

    Merge pull request #335 from jaredhoberock/issue-334

    Add counting_iterator::operator-(counting_iterator)

82 % g++ --version
g++ (Gentoo 4.9.4 p1.0, pie-0.6.4) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

83 % g++ -I ../agency/ -std=c++11 main.cpp
jaredhoberock commented 7 years ago

Thanks. I also see a problem with g++-4.8. The error log begins with:

In file included from ./agency/execution/execution_agent.hpp:13:0,
                 from ./agency/detail/control_structures/agent_shared_parameter_factory_tuple.hpp:6,
                 from ./agency/detail/control_structures/bulk_invoke_execution_policy.hpp:11,
                 from ./agency/detail/control_structures/bulk_async_execution_policy.hpp:8,
                 from ./agency/bulk_async.hpp:8,
                 from ./agency/agency.hpp:18,
                 from test.cpp:1:
./agency/detail/memory/resource/arena_resource.hpp:42:57: error: ‘max_align_t’ is not a member of ‘std’
 template<std::size_t N, std::size_t alignment = alignof(std::max_align_t)>
                                                         ^
./agency/detail/memory/resource/arena_resource.hpp:42:57: note: suggested alternative:
In file included from ./agency/detail/integer_sequence.hpp:4:0,
                 from ./agency/detail/control_structures/bind.hpp:4,
                 from ./agency/async.hpp:4,
                 from ./agency/agency.hpp:17,
                 from test.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h:425:3: note:   ‘max_align_t’
 } max_align_t;
...

Does this agree with what you observe? In the meantime, I'll try to get access to g++-4.9.

I have been using this g++, which doesn't appear to produce the problems from your new example:

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
alobb commented 7 years ago

Interestingly, clang-3.7.1 compiles it without errors, so this might be an issue of the compiler being too old. Sorry for not including the error, here is the full text: error.txt

It looks like the error messages from g++-4.9 aren't the same as g++-4.8.

jaredhoberock commented 7 years ago

Thanks for posting the error message. Yes, this is a case where a bug present in an older version of gcc is causing a problem parsing the code. There may be a way to rewrite the code to workaround the issue.