[hpx-users] Integration of HPX with GUI mainloop

2017-12-04 Thread Andreas Buhr
Dear HPXlers,

I am wondering how to integrate HPX with GUI applications. I'd like to
have one GUI locality where e.g. a Qt application is running. Then I'd
like to trigger GUI events from HPX actions.

Problem: Both HPX and Qt want the mainloop.

I was able to do a similar thing with ZeroMQ and Qt. There I gave the
mainloop to Qt. ZeroMQ then provides a file descriptor and I can use a
"QSocketNotifier" that triggers whenever the ZeroMQ-socket receives an
event. The QSocketNotifier is then connected to a ZeroMQ event handler.
That way, both parts are happy.

How would you do that with HPX?

Thanks a lot in advance,
best regards,
Andreas
___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users


Re: [hpx-users] Integration of HPX with GUI mainloop

2017-12-04 Thread Hartmut Kaiser

> I am wondering how to integrate HPX with GUI applications. I'd like to
> have one GUI locality where e.g. a Qt application is running. Then I'd
> like to trigger GUI events from HPX actions.
> 
> Problem: Both HPX and Qt want the mainloop.

HPX does not 'want' access to the main loop.

> I was able to do a similar thing with ZeroMQ and Qt. There I gave the
> mainloop to Qt. ZeroMQ then provides a file descriptor and I can use a
> "QSocketNotifier" that triggers whenever the ZeroMQ-socket receives an
> event. The QSocketNotifier is then connected to a ZeroMQ event handler.
> That way, both parts are happy.
> 
> How would you do that with HPX?

There are several ways how to integrate Qt with HPX and let it run its main
loop. 

There is this example which explicitly drives Qt using HPX's
main_pool_executor:
https://github.com/STEllAR-GROUP/hpx/tree/master/examples/qt.
There is also a way to leave Qt running on the main thread (i.e. the one
that called
main()):https://github.com/STEllAR-GROUP/hpx/blob/master/examples/quickstart
/use_main_thread.cpp.

Both options allow to coordinate things between the two worlds. I'd suggest
to go with the solution based on the executor.

HTH
Regards Hartmut
---
http://boost-spirit.com
http://stellar.cct.lsu.edu



___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users


Re: [hpx-users] Integration of HPX with GUI mainloop

2017-12-05 Thread Andreas Buhr
On 12/04/2017 07:37 PM, Hartmut Kaiser wrote:
> There are several ways how to integrate Qt with HPX and let it run its main
> loop. 
> 
> There is this example which explicitly drives Qt using HPX's
> main_pool_executor:
> https://github.com/STEllAR-GROUP/hpx/tree/master/examples/qt.

Wow, thanks a lot for your quick help and reply. But the example is
confusing me a bit.

The main problem when using a parallel system and Qt is that most member
functions of widgets must not be called from a thread other than the
main thread (GUI-thread). So when a thread other than the main thread
wants to trigger some GUI change, it has to communicate with the GUI
thread and the GUI thread then does the GUI change.

This principle is ignored in the example: In the example [1], an HPX
thread calls widget::add_label which in turn calls QListWidget::addItem.
I think this should not happen, even when protected with a mutex-lock.

I modified the code to be correct in my understanding: The widget has
now two threadsafe interface functions: threadsafe_add_label and
threadsafe_run_finished, both of which do not interact with GUI objects.
They might be called from any thread. They in turn schedule the
execution of corresponding functions within the GUI thread.

Would you agree? I am not a GUI expert, so I'm not sure about my solution.
I created a pull request [2]. Feel free to accept or reject...

best regards,
Andreas


[1]
https://github.com/STEllAR-GROUP/hpx/blob/2ec00bc39b5d384aeda7cdb58a893680a057e2d2/examples/qt/widget.cpp#L53

[2]
https://github.com/STEllAR-GROUP/hpx/pull/3051



signature.asc
Description: OpenPGP digital signature
___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users


Re: [hpx-users] Integration of HPX with GUI mainloop

2017-12-05 Thread Hartmut Kaiser
Andreas,

> > There is this example which explicitly drives Qt using HPX's
> > main_pool_executor:
> > https://github.com/STEllAR-GROUP/hpx/tree/master/examples/qt.
> 
> Wow, thanks a lot for your quick help and reply. But the example is
> confusing me a bit.
> 
> The main problem when using a parallel system and Qt is that most member
> functions of widgets must not be called from a thread other than the
> main thread (GUI-thread). So when a thread other than the main thread
> wants to trigger some GUI change, it has to communicate with the GUI
> thread and the GUI thread then does the GUI change.
> 
> This principle is ignored in the example: In the example [1], an HPX
> thread calls widget::add_label which in turn calls QListWidget::addItem.
> I think this should not happen, even when protected with a mutex-lock.
> 
> I modified the code to be correct in my understanding: The widget has
> now two threadsafe interface functions: threadsafe_add_label and
> threadsafe_run_finished, both of which do not interact with GUI objects.
> They might be called from any thread. They in turn schedule the
> execution of corresponding functions within the GUI thread.
> 
> Would you agree? I am not a GUI expert, so I'm not sure about my solution.
> I created a pull request [2]. Feel free to accept or reject...

Thanks for this fix. I don't know anything about Qt but your patch looks sane 
to me. Thomas might know more, he wrote the example in the first place.

Regards Hartmut
---
http://boost-spirit.com
http://stellar.cct.lsu.edu

> 
> best regards,
> Andreas
> 
> 
> [1]
> https://github.com/STEllAR-
> GROUP/hpx/blob/2ec00bc39b5d384aeda7cdb58a893680a057e2d2/examples/qt/widget
> .cpp#L53
> 
> [2]
> https://github.com/STEllAR-GROUP/hpx/pull/3051


___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users


Re: [hpx-users] Integration of HPX with GUI mainloop

2017-12-05 Thread Thomas Heller
Am 05.12.2017 2:13 nachm. schrieb "Andreas Buhr" :

On 12/04/2017 07:37 PM, Hartmut Kaiser wrote:
> There are several ways how to integrate Qt with HPX and let it run its
main
> loop.
>
> There is this example which explicitly drives Qt using HPX's
> main_pool_executor:
> https://github.com/STEllAR-GROUP/hpx/tree/master/examples/qt.

Wow, thanks a lot for your quick help and reply. But the example is
confusing me a bit.

The main problem when using a parallel system and Qt is that most member
functions of widgets must not be called from a thread other than the
main thread (GUI-thread). So when a thread other than the main thread
wants to trigger some GUI change, it has to communicate with the GUI
thread and the GUI thread then does the GUI change.

This principle is ignored in the example: In the example [1], an HPX
thread calls widget::add_label which in turn calls QListWidget::addItem.
I think this should not happen, even when protected with a mutex-lock.

I modified the code to be correct in my understanding: The widget has
now two threadsafe interface functions: threadsafe_add_label and
threadsafe_run_finished, both of which do not interact with GUI objects.
They might be called from any thread. They in turn schedule the
execution of corresponding functions within the GUI thread.

Would you agree? I am not a GUI expert, so I'm not sure about my solution.
I created a pull request [2]. Feel free to accept or reject...


You are most certainly correct. Thanks for catching this. Did you run into
any problems with what we have so far?


best regards,
Andreas


[1]
https://github.com/STEllAR-GROUP/hpx/blob/2ec00bc39b5d384aeda7cdb58a8936
80a057e2d2/examples/qt/widget.cpp#L53

[2]
https://github.com/STEllAR-GROUP/hpx/pull/3051


___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users
___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users


Re: [hpx-users] Integration of HPX with GUI mainloop

2017-12-05 Thread Andreas Buhr
Hi Thomas, thanks for your reply.

On 12/05/2017 04:02 PM, Thomas Heller wrote:
> Am 05.12.2017 2:13 nachm. schrieb "Andreas Buhr"  >:

[snip]

> This principle is ignored in the example: In the example [1], an HPX
> thread calls widget::add_label which in turn calls QListWidget::addItem.
> I think this should not happen, even when protected with a mutex-lock.
> 
> I modified the code to be correct in my understanding: The widget has
> now two threadsafe interface functions: threadsafe_add_label and
> threadsafe_run_finished, both of which do not interact with GUI objects.
> They might be called from any thread. They in turn schedule the
> execution of corresponding functions within the GUI thread.
> 
> Would you agree? I am not a GUI expert, so I'm not sure about my
> solution.
> I created a pull request [2]. Feel free to accept or reject...
> 
> 
> You are most certainly correct. Thanks for catching this. Did you run
> into any problems with what we have so far?

No, I haven't seen any problems with the example. However, I am looking
for the right design for a larger application, so I'd like to get it right.

best,

Andreas

___
hpx-users mailing list
hpx-users@stellar.cct.lsu.edu
https://mail.cct.lsu.edu/mailman/listinfo/hpx-users