Andrey, I thought I answered this, here: http://thread.gmane.org/gmane.comp.lib.hpx.user/712/focus=714.
Regards Hartmut --------------- http://boost-spirit.com http://stellar.cct.lsu.edu > -----Original Message----- > From: [email protected] [mailto:hpx-users- > [email protected]] On Behalf Of Andrey Semashev > Sent: Tuesday, April 5, 2016 4:42 PM > To: [email protected] > Subject: Re: [hpx-users] Problems with parallel execution > > On Sat, Mar 19, 2016 at 5:39 PM, Andrey Semashev > <[email protected]> wrote: > > Hi, > > > > I'm trying to learn how HPX works and whether it is applicable to my > needs. > > Basically, what I'm trying to do is to parallelize parts of my code that > are > > currently running sequentially, within a number of OS threads. I've > written > > the following simple code to see how HPX can be used to achieve what I > want: > > > > #include <unistd.h> > > #include <iostream> > > #include <thread> > > #include <vector> > > #include <iterator> > > #include <hpx/hpx_init.hpp> > > #include <hpx/parallel/execution_policy.hpp> > > #include <hpx/parallel/algorithms/for_each.hpp> > > > > unsigned int values[1000] = {}; > > > > void process(unsigned int& value) > > { > > // Some useful work is performed here > > sleep(1000); > > } > > > > void my_thread() > > { > > // Assume this thread is getting data > > // from some kind of blocking IO. > > // I want to process this data in multiple > > // threads. > > hpx::parallel::for_each_n(hpx::parallel::par, > > std::begin(values), 1000, &process); > > } > > > > int hpx_main(int argc, char* argv[]) > > { > > std::thread th(&my_thread); > > > > th.join(); > > > > return hpx::finalize(); > > } > > > > int main(int argc, char *argv[]) > > { > > std::vector< char* > args; > > for (int i = 0; i < argc; ++i) > > args.push_back(argv[i]); > > > > // Use all hardware threads > > args.push_back(const_cast< char* >("--hpx:threads")); > > args.push_back(const_cast< char* >("all")); > > > > return hpx::init(args.size(), args.data()); > > } > > > > My expectation of this code is that hpx::parallel::for_each_n would > offload > > some iterations to the threads HPX spawns in its thread pool, and the > rest > > is done in the my_thread thread. I would expect all iterations to be > done in > > the my_thread thread if all HPX threads are busy doing something else, > but > > in this example there's no other work to do, so this should not happen. > > > > However, that is exactly what I'm observing. The process function is > only > > called in one thread - my_thread. There are multiple HPX threads > started, > > and they are doing something (i.e. all but one CPU logical cores are > > heavilly loaded), but they are not calling process. > > > > So my questions are: > > > > 1. Is what I'm trying to do implementable with HPX? > > 2. Am I doing something wrong in the above code? > > 3. What are HPX threads doing while they apparently are not doing any > useful > > work? Is it normal for them to load the CPU for no apparent reason? > > > > I'm using HPX 0.9.11 with Boost 1.60 on Kubuntu 15.10 x86_64 (gcc 5.2). > I'm > > running the test app with no command line arguments and no ini files. > > > > Thanks. > > Ping? > _______________________________________________ > hpx-users mailing list > [email protected] > https://mail.cct.lsu.edu/mailman/listinfo/hpx-users _______________________________________________ hpx-users mailing list [email protected] https://mail.cct.lsu.edu/mailman/listinfo/hpx-users
