Search code examples
c++parallel-processinghpx

Localities in parallelism


New to parallelism and learning the ropes to HPX with C++. I'm looking at a specific hello-word example that will print hello world on every OS-thread on every locality, some output would look like:

hello world from OS-thread 1 on locality 0
hello world from OS-thread 1 on locality 1
hello world from OS-thread 0 on locality 0
hello world from OS-thread 0 on locality 1

My question is, when the program output on locality x, what exactly does locality mean? I understand OS-thread but I'm not quite sure what the program means by which locality.

Example of some code inside HPX main this isn't necessarily required by my question, but it does include multiple calls to finding localities which relate to topic.

int hpx_main()
{
    {
        // Get a list of all available localities.
        std::vector<hpx::naming::id_type> localities =
            hpx::find_all_localities();

        // Reserve storage space for futures, one for each locality.
        std::vector<hpx::lcos::future<void> > futures;
        futures.reserve(localities.size());

        BOOST_FOREACH(hpx::naming::id_type const& node, localities)
        {
            // Asynchronously start a new task. The task is encapsulated in a
            // future, which we can query to determine if the task has
            // completed.
            typedef hello_world_foreman_action action_type;
            futures.push_back(hpx::async<action_type>(node));
        }

        // The non-callback version of hpx::lcos::wait takes a single parameter,
        // a future of vectors to wait on. hpx::lcos::wait only returns when
        // all of the futures have finished.
        hpx::lcos::wait(futures);
    }

    // Initiate shutdown of the runtime system.
    return hpx::finalize();
}

Solution

  • From what I understand from their documentation - you can treat Locality as the number of processes that execute the application.
    lets say 2 servers execute your program, the first one will execute locality 0, and the second locality 1.
    That way you can know which process, which executes the same code, is lets say the server (locality 0) and which is the client (locality 1).

    In addition, each process can run multiple threads, which is visible as the number of os_threads.

    follow that example: http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/examples/hello_world.html

    and these command line options: http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/getting_started/commandline.html

    This is the explanation of how to use multiple localities: http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/getting_started/unix_pbs.html

    I think the best way to understand it is to play with the values of --hpx:node and --hpx:threads.

    In addition - I think the openmpi documentation is a bit better for understanding the terms...

    Although not sure I helped, I hope I did.