2

As a continuation of this question and the subsequent answer, does anyone know how to have a job created using the Parallel Computing Toolbox (using createJob and createTask) access external toolboxes? Is there a configuration parameter I can specify when creating the function to specify toolboxes that should be loaded?

Community
  • 1
  • 1
eykanal
  • 26,437
  • 19
  • 82
  • 113

2 Answers2

3

According to this section of the documentation, one way you can do this is to specify either the 'PathDependencies' property or the 'FileDependencies' property of the job object so that it points to the functions you need the job's workers to be able to use.

You should be able to point the way to the KbCheck function in PsychToolbox, along with any other functions or directories needed for KbCheck to work properly. It would look something like this:

obj = createJob('PathDependencies',{'path_to_KbCheck',...
                                    'path_to_other_PTB_functions'});
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • 1
    Note that that form of createJob uses the default parallel configuration - if you have a scheduler object, you can also use sched.createJob( ... ) – Edric Dec 13 '10 at 07:57
  • Thanks a lot for pointing these out. I really wonder why they hid all that information in the "Using a third-party scheduler" part of the manual. In any event, I really apprecite the help! – eykanal Dec 13 '10 at 18:16
2

A few comments, based on my work troubleshooting this:

  • It appears that there are inconsistencies with how well nested functions and anonymous functions work with the Parallel Computation toolkit. I was unable to get them to work, while others have been able to. (Also see here.) As such, I would recommend having each function stored in it's own file, and including those files using the PathDependencies or FileDependencies properties, as described by gnovice above.

  • It is very hard to troubleshoot the Parallel Computation toolkit, as everything happens outside your view. Use breakpoints liberally in your code, and the inspect command is your friend. Also note that if there is an error, task objects will contain an error parameter, which in turn will contain ErrorMessage string, and possibly the Error.causes MException object. Both of these were immensely useful in debugging.

  • When including Psychtoolbox, you need to do it as follows. First, create a jobStartup.m file with the following lines:

    PTB_path = '/Users/eliezerk/Documents/MATLAB/Psychtoolbox3/';
    addpath( PTB_path );
    cd( PTB_path );
    SetupPsychtoolbox;
    

    However, since the Parallel Computation toolkit can't handle any graphics functionality, running SetupPsychtoolbox as-is will actually cause your thread to crash. To avoid this, you need to edit the PsychtoolboxPostInstallRoutine function, which is called at the very end of SetupPsychtoolbox. Specifically, you want to comment out the line AssertOpenGL (line 496, as of the time of this answer; this may change in future releases).

Community
  • 1
  • 1
eykanal
  • 26,437
  • 19
  • 82
  • 113
  • I wonder if the inconsistencies in being able to use nested/anonymous functions is related at all to the versions of MATLAB or the Parallel Computing Toolbox being used. I had no problems when using R2009a for each (MATLAB version 7.8.0.347 and PCT version 4.1). – gnovice Dec 13 '10 at 18:25
  • @gnovice - I'm running MATLAB 7.8.0.347 (R2009a) and PCT 4.1, so I guess not. I'm very curious as to the cause, but I don't think I have enough info to file a useful bug report about it. – eykanal Dec 13 '10 at 18:48