text: //  Copyright (c) 2014 Hartmut Kaiser
  //
  //  SPDX-License-Identifier: BSL-1.0
  //  Distributed under the Boost Software License, Version 1.0. (See accompanying
  //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  
  #include <pika/local/init.hpp>
  #include <pika/parallel/datapar.hpp>
  
  #include <cstddef>
  #include <iostream>
  #include <string>
  #include <vector>
  
  #include "../algorithms/foreach_tests.hpp"
  
  ///////////////////////////////////////////////////////////////////////////////
  template <typename IteratorTag>
  void test_for_each_n()
  {
      using namespace pika::execution;
  
      test_for_each_n(simd, IteratorTag());
      test_for_each_n(par_simd, IteratorTag());
  
      test_for_each_n_async(simd(task), IteratorTag());
      test_for_each_n_async(par_simd(task), IteratorTag());
  }
  
  void for_each_n_test()
  {
      test_for_each_n<std::random_access_iterator_tag>();
      test_for_each_n<std::forward_iterator_tag>();
  }
  
  ///////////////////////////////////////////////////////////////////////////////
  int pika_main(pika::program_options::variables_map& vm)
  {
      unsigned int seed = (unsigned int) std::time(nullptr);
      if (vm.count("seed"))
          seed = vm["seed"].as<unsigned int>();
  
      std::cout << "using seed: " << seed << std::endl;
      std::srand(seed);
  
      for_each_n_test();
      return pika::local::finalize();
  }
  
  int main(int argc, char* argv[])
  {
      // add command line option which controls the random number generator seed
      using namespace pika::program_options;
      options_description desc_commandline(
          "Usage: " PIKA_APPLICATION_STRING " [options]");
  
      desc_commandline.add_options()("seed,s", value<unsigned int>(),
          "the random number generator seed to use for this run");
  
      // By default this test should run on all available cores
      std::vector<std::string> const cfg = {"pika.os_threads=all"};
  
      // Initialize and run pika
      pika::local::init_params init_args;
      init_args.desc_cmdline = desc_commandline;
      init_args.cfg = cfg;
  
      PIKA_TEST_EQ_MSG(pika::local::init(pika_main, argc, argv, init_args), 0,
          "pika main exited with non-zero status");
  
      return pika::util::report_errors();
  }
  