Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding global_factorial example implemented based on global_init #3231

Closed
wants to merge 4 commits into from

Conversation

NK-Nikunj
Copy link
Member

Proposed Changes

This PR shows a very basic implementation of the GSoC project "A C++ Runtime Replacement".

The example is working and after building an executable is created by the name of global_factorial ( to keep it different from factorial, which is already an example in quickstart ) in the bin directory.

@NK-Nikunj NK-Nikunj changed the title Mini gsoc Adding global_factorial example implemented based on global_init Mar 12, 2018
@hkaiser
Copy link
Member

hkaiser commented Mar 13, 2018

@NK-Nikunj I thought about this a bit more. While a global object is a very elegant solution, it will not provide us with a seamless integration of HPX into arbitrary existing applications. For that we would need to invoke the C-main function on an HPX thread (very much what happens now if #include <hpx/hpx_main.hpp> is used - but more elegantly). Any ideas you might have would be appreciated.

@NK-Nikunj
Copy link
Member Author

@hkaiser I am investigating ways through which we could invoke the C-main function on an HPX thread.

@NK-Nikunj
Copy link
Member Author

@hkaiser I have implemented the runtime system with following features:-

  • main now runs as an HPX thread. This means that all hpx components can be called in main
  • Things now run without getting into hpx_main
  • User now has to call hpx::complete() to start the termination of the program
  • After correcting initialization sequence, everything will run seamlessly

@hkaiser
Copy link
Member

hkaiser commented Mar 16, 2018

@NK-Nikunj could you address the reported inspect problems, please (see: https://9795-4455628-gh.circle-artifacts.com/0/tmp/circle-artifacts.E1deIzW/hpx_inspect_report.html)?

@hkaiser
Copy link
Member

hkaiser commented Mar 17, 2018

Unfortunately there are still some tabs in those files: https://9800-4455628-gh.circle-artifacts.com/0/tmp/circle-artifacts.nkLjCos/hpx_inspect_report.html

// Finalize everything
destruct destroy;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Wouldn't invoking hpx::finalize() from the main function of the application trigger the destruction of the global object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser I was not aware if hpx::finalize() trigger destruction of the global objects as well. So, I created an alternative way of hpx::complete() which would first destruct runtime system then de-initialize the initialization sequences that will be implemented in manage_global_runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hpx::finalize() informs the runtime that it is safe to exit. This should eventually cause the runtime to exit and the main application should terminate. At this point the system calls the destructors of all global objects (after the C-main function returned).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so calling hpx::finalize() in main itself should work properly. I'll make amendments to my code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, wasn't the goal of the whole example to show that the user does not need to invoke any special functionality in order to use HPX?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this example do differently compared to the existing example init_globally?

Copy link
Member Author

@NK-Nikunj NK-Nikunj Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example runs main directly as hpx thread without using hpx_main. This gives main function complete functionalities of an hpx thread i.e. futures and async can run without giving null id runtime error. In init_globally you could not get all functionalities of hpx thread in main, I received null id error for futures and async. This is because main is registered as hpx thread, so only a few components can be used.

Furthermore, I felt that this implementation is better since it completely drops the idea of hpx_main, which was the key aspect of my GSoC project (i.e. running things directly from main without going through a special function).

@msimberg msimberg removed this from the 1.1.0 milestone Mar 22, 2018
@NK-Nikunj
Copy link
Member Author

Closing this pr wrt #3357 which is a better implementation as compared to the given pr.

@NK-Nikunj NK-Nikunj closed this Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants