Sharing C mex variables Between Client and parallel Workers

4 visualizaciones (últimos 30 días)
Amr Mohamed
Amr Mohamed el 19 de Abr. de 2021
Comentada: Walter Roberson el 20 de Abr. de 2021
How can I use a structure variable defined in C mex file and assigned in Client before entering spmd workers, inside this parallel workers with the same values?
When a global structure variable values changes insided C mex function in matlab client then the same C mex function is executed from the spmd parallel workers; the values of the global structure variable is returned to zeros inside the parallel worker (I'm using mexMakeMemoryPersistent function).
How can I share the structure variable between Client and parallel Workers?

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Abr. de 2021
mexMakeMemoryPersistent is the equivalent of persistent and is not the equivalent of global .
If you need changes in one worker (or on the client) to affect all of the workers, then you need to do one of:
  • program shared memory (operating system specific; Mac and Linux use POSIX standard shared memory, Windows does its own shared memory)
  • matFile() to access a shared file (I am not really confident this will work reliably)
  • memmapfile() https://www.mathworks.com/help/matlab/ref/memmapfile.html
  • use dataqueues to send between client and workers, with the client acting as the switchyard to distribute any changes to all workers
  2 comentarios
Amr Mohamed
Amr Mohamed el 20 de Abr. de 2021
-Aren't file memmapfile(), and use dataqueues to send between client and workers for variables not in a C mex (defined inside matlab)? I need to do that inside the C mex file.
I don't think those solutions may help me; As I have a complex C structure variable which contains many variables and pointers inside a C mex file and I want to fill this strucure variable from matlab client to be used inside matlab parallel workers.
Walter Roberson
Walter Roberson el 20 de Abr. de 2021
I have a complex C structure variable which contains many variables and pointers
Classical workers are in different processes; pointers shared would be useless, unless the pointers were to shared memory that was mapped into a fixed address location inside the process.
There is a File Exchange contribution for Shared Memory for Mac and Linux (not Windows). Reports are that it worked until MATLAB changed the headers for variables when it changed representation of complex a couple of releases ago, so it might potentially be repairable for current versions.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by