PTB OpenGL Error and parallel computing

Hello everyone,

I’m having some trouble with PTB and parallel computing. I am trying to run a code that uses PTB to do SSVEP, and run another program that takes in data from a dry EEG headset. It would be easiest to run these two scripts together in tandem with some sort of parallel computing function such as batch or parfeval, but I am running into issues with opening the OpenGL features of PTB with the parallel computing functions. Here is an example of the error I am getting:

Task with properties:

               ID: 1
            State: finished
         Function: @parallel.internal.cluster.executeFunction
           Parent: Job 39
    StartDateTime: 22-Jul-2021 10:31:15
 Running Duration: 0 days 0h 0m 6s

            Error: Unable to read file 
                   'C:\Users\ ......... \AppData\Local\Temp\tp3d3c4d59_5e73_48a5_aa9a_6a8e75cf411drp9800\a
                   \PsychOpenGL\MOGL\core\oglconst.mat'. No such file or directory.
      Error Stack: InitializeMatlabOpenGL (line 154)
                   PsychImaging>PostConfiguration (line 3639)
                   PsychImaging (line 2472)
                   RadialCheckers (line 29)
         Warnings:

Does anyone know of a workaround or a solution to this issue?

This error was given with the parfeval command, but the same thing comes up with batch as well.

Thanks!

There are many restrictions to using the parallel computing functions in MATLAB, which are fundamentally not designed for parallel processes, but parallel algorithms. Really the easiest thing is to simply run 2 instances of MATLAB. You can launch a console version of MATLAB from your main GUI one, then they can talk to each other (inter-process communication, IPC) using many different mechanisms. The strong advantage of this is those two instances can be on the same machine, or you can easily just move one to a different machine. I use TCP/UDP via PTB’s pnet library to communicate with an electrophysiology tool, but probably if I was doing this fresh I’d consider something like ZeroMQ.

1 Like

Ian is right. However, many of PTB’s function themselves can run in the background, e.g., all sound and input functions, so often one doesn’t need to run scripts in parallel. And even for visual stimulation there is some parallelism achievable, as demonstrated in AsyncFlipTest.m and MultiWindowLockStepTest.m, and even more so with standard Flip’s if one uses Linux on recommended AMD, Intel, … graphics, e.g., PerceptualVBLSyncTestFlipInfo.m and PerceptualVBLSyncTestFlipInfo2.m.

So often one can avoid the need for running scripts in parallel. Otherwise Ian’s approach is a good one that i used myself in the past for realtime-critical experimental setups.

-mario

1 Like

Ian, could you expand on why ZeroMQ over UDP? Good knowledge to have. Thanks!

Hi Dee, probably for a very simple 1 client <-> 1 server architecture, over a dedicated ethernet switch, UDP or TCP is fine. I think the big advantage of ZeroMQ is robustness and flexibility. ZeroMQ can scale to different architectures (i.e. more than 1 client, only clients without a server), and has a ton of robustness built in so you can move clients across machines (future-proofing), deal with delays and all other sorts of stuff. The documentation is great too. I’m no expert, but I trust people who are, and ZeroMQ has become a standard IPC mechanism in this regard…

The main downside of ZeroMQ? MATLAB’s interface to ZeroMQ is not so well maintained; Octave is actually better in this regard…