Пример #1
0
        std::size_t handle_num_threads(util::manage_config& cfgmap,
            boost::program_options::variables_map& vm,
            util::batch_environment& env, bool using_nodelist)
        {
            std::size_t batch_threads = env.retrieve_number_of_threads();
            if(batch_threads == std::size_t(-1)) { batch_threads = 1; }
            std::string threads_str = cfgmap.get_value<std::string>(
                "hpx.os_threads", "");

            if ("all" == threads_str) {
                cfgmap.config_["hpx.os_threads"] =
                    boost::lexical_cast<std::string>(
                        thread::hardware_concurrency());
            }

            std::size_t threads = cfgmap.get_value<std::size_t>(
                "hpx.os_threads", batch_threads);

            if ((env.run_with_pbs() || env.run_with_slurm()) &&
                using_nodelist && (threads > batch_threads))
            {
                detail::report_thread_warning(env.get_batch_name(),
                    threads, batch_threads);
            }

            if (vm.count("hpx:threads")) {
                threads_str = vm["hpx:threads"].as<std::string>();
                if ("all" == threads_str)
                    threads = thread::hardware_concurrency(); //-V101
                else
                    threads = boost::lexical_cast<std::size_t>(threads_str);

                if (threads == 0)
                {
                    throw std::logic_error("Number of --hpx:threads "
                        "must be greater than 0");
                }

                if ((env.run_with_pbs() || env.run_with_slurm()) &&
                    using_nodelist && (threads > batch_threads))
                {
                    detail::report_thread_warning(env.get_batch_name(),
                        threads, batch_threads);
                }

#if defined(HPX_MAX_CPU_COUNT)
                if (threads > HPX_MAX_CPU_COUNT) {
                    throw std::logic_error("Requested more than "
                        BOOST_PP_STRINGIZE(HPX_MAX_CPU_COUNT)" --hpx:threads "
                        "to use for this application, use the option "
                        "-DHPX_MAX_CPU_COUNT=<N> when configuring HPX.");
                }
#endif
            }
            return threads;
        }
Пример #2
0
        std::size_t get_number_of_default_cores(util::batch_environment& env)
        {
            threads::topology& top = threads::create_topology();

            std::size_t batch_threads = env.retrieve_number_of_threads();
            std::size_t num_cores = top.get_number_of_cores();
            if(batch_threads == std::size_t(-1))
                return num_cores;

            // assuming we assign the first N cores ...
            std::size_t core = 0;
            for(; core < num_cores; ++core)
            {
                batch_threads -= top.get_number_of_core_pus(core);
                if(batch_threads == 0) break;
            }

            return core + 1;
        }