<commit_before>#include <agency/cuda/grid_executor.hpp>
#include <algorithm>
#include <iostream>


__managed__ int increment_me;

struct increment_and_return_void
{
  template<class Index>
  __device__
  void operator()(const Index&, int& past)
  {
    atomicAdd(&increment_me, past);
  }
};


template<class Executor>
void test()
{
  using executor_type = Executor;

  using traits = agency::executor_traits<executor_type>;

  {
    // then_execute returning user-specified container
    
    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    using container_type = typename executor_type::template container<int>;

    using index_type = typename executor_type::index_type;

    auto fut = exec.template then_execute<container_type>([] __device__ (index_type idx, int& past, int& outer_shared_arg, float& inner_shared_arg)
    {
      assert(inner_shared_arg == 13.0f);
      return past + outer_shared_arg;
    },
    shape,
    past,
    7,
    13.0f);

    auto got = fut.get();

    assert(got == std::vector<int>(got.size(), 13 + 7));
  }

//  {
//    // then_execute returning default container
//    
//    executor_type exec;
//
//    typename executor_type::shape_type shape{10,10};
//
//    auto past = traits::template make_ready_future<int>(exec, 13);
//
//    using index_type = typename traits::index_type;
//
//    auto fut = traits::then_execute(exec, [] __device__ (index_type idx, int& past)
//    {
//      return past;
//    },
//    shape,
//    past);
//
//    auto result = fut.get();
//
//    std::vector<int> ref(result.size(), 13);
//    assert(std::equal(ref.begin(), ref.end(), result.begin()));
//  }
//
//  {
//    // then_execute returning void
//    
//    executor_type exec;
//
//    typename executor_type::shape_type shape{10,10};
//
//    auto past = traits::template make_ready_future<int>(exec, 13);
//
//    increment_me = 0;
//
//    using index_type = typename traits::index_type;
//
//    // XXX don't use a __device__ lambda here because we can't reliably compute its return type
//    auto fut = traits::then_execute(exec, increment_and_return_void(), shape, past);
//
//    fut.wait();
//
//    assert(increment_me == shape[0] * shape[1] * 13);
//  }
}
<commit_msg>Finish up initial implementation of test_multi_agent_then_execute_with_shared_inits.cu<commit_after>#include <agency/cuda/grid_executor.hpp>
#include <algorithm>
#include <iostream>


__managed__ int increment_me;

struct increment_and_return_void
{
  template<class Index>
  __device__
  void operator()(const Index&, int& past, int& outer_shared_arg, int& inner_shared_arg)
  {
    atomicAdd(&increment_me, past + outer_shared_arg + inner_shared_arg);
  }
};


struct sum_13_7_and_42
{
  template<class Index, class T1, class T2, class T3>
  __device__
  int operator()(const Index&, T1& past, T2& outer_shared_arg, T3& inner_shared_arg)
  {
    assert(past == 13);
    assert(outer_shared_arg == 7);
    assert(inner_shared_arg == 42);
    return past + outer_shared_arg + inner_shared_arg;
  }
};


template<class Executor>
void test()
{
  using executor_type = Executor;

  using traits = agency::executor_traits<executor_type>;

  {
    // then_execute returning user-specified container
    
    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    using container_type = typename executor_type::template container<int>;

    using index_type = typename executor_type::index_type;

    auto fut = traits::template then_execute<container_type>(exec, sum_13_7_and_42(), shape, past, 7, 42.0f);

    auto got = fut.get();

    assert(got == std::vector<int>(got.size(), 13 + 7 + 42));
  }

  {
    // then_execute returning default container
    
    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    using index_type = typename traits::index_type;

    auto fut = traits::then_execute(exec, sum_13_7_and_42(), shape, past, 7, 42.0f);

    auto result = fut.get();

    std::vector<int> ref(result.size(), 13 + 7 + 42);
    assert(std::equal(ref.begin(), ref.end(), result.begin()));
  }

  {
    // then_execute returning void
    
    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    increment_me = 0;

    using index_type = typename traits::index_type;

    auto fut = traits::then_execute(exec, increment_and_return_void(), shape, past, 7, 42);

    fut.wait();

    assert(increment_me == shape[0] * shape[1] * (13 + 7 + 42));
  }
}

{'fraction_non_alphanumeric': 0.1368620835090679, 'fraction_numerical': 0.022775200337410376, 'mean_word_length': 3.6003879728419013, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5106642', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1560, 'n_words': 350}