pmode is an interactive parallel environment enhanced with a GUI. For a small number of workers , each has its own dedicated sub-display-window. This is an excellent tool for learning the PCT and for parallel code development and debugging. Starting pmode automatically launches an interactive batch job that allocates the requested workers.

  • To start pmode (with default configuration)

    >> pmode start  % "help pmode" for more details
    Starting pmode using the parallel configuration 'SGE'.
    Job output will be written to: /usr6/kadin/examples/pct/Job3.mpiexec.out
    QSUB output: Your job 58551 ("Job3") has been submitted
    
    Waiting for parallel job to start...
    Connected to a pmode session with 4 labs.

    In the above, pmode was invoked with default configuration, which is defined by the SCC Open Grid Scheduler (OGS) batch scheduler. The last printed line indicated that 4 labs (workers) have been assigned. You could override the default with “pmode start 8” to request 8 labs. A separate GUI window will pop up which consists of a group of sub-windows displaying data on the local labs in response to commands issued at P>> at the bottom of this window. The P>> prompt distinguishes itself from the regular MATLAB prompt (>>) as being dedicated to pmode.

    To end pmode, do either of the below:

    >> pmode quit    % quit|exit|close from the MATLAB prompt
    
    
    P>> exit         % exit the Parallel Command Window
  • To copy data from a worker (lab) to the client (MATLAB workspace)

    P>> pmode lab2client y 3 yc  % copy y of lab 3 to yc on client
  • To copy data from client to workers

    P>> pmode client2lab yc 2 y  % copy yc on client to y on lab 2
  • Make plots

    pmode environment does not support graphics display. To make plots:

    1. Copy data from the workers to the MATLAB client
    2. Make plots in the MATLAB window (>>).

    Here is an example.

    P>> x = 2*labindex;     % [2 4 6 8]
    P>> D = zeros(1,numlabs,codistributor());   % create a shared array
    P>> for i=drange(1:numlabs), D(i) = x; end  % saves x in D according to labindex
    P>> y = gather(D, 1);      % gather from all labs to lab 1
    P>> pmode lab2client y 1 yc % pmode lab2client labvar lab clientvar

    Now, switch to the MATLAB window.

    >> yc     % verify the content of yc in the MATLAB window
    yc = 2 4 6 8
    >> plot(yc)   % plot a line in the MATLAB window

    Alternatively, D can be generated without using drange:

    P>> D = ones(1,numlabs,codistributor()) * x;
  • matlabpool + spmd is equivalent to pmode but without a graphics interface or a few other commands such as whos.
  • If you are developing a procedure via pmode, once all the steps have been worked out, you can capture the history by selecting lines on the command list on the left pane of the pmode window and save it into a script file for batch applications. Specifically, to select consecutive lines, press the shift key and left-mouse click the beginning and end lines. To select arbitrary lines, press the control key and use the left-mouse button to select the individual lines. It is important to note that pmode operations and matlabpool + spmd operations are not completely conformal. Alternatively, diary can be used to capture the commands exercised. Some conversion may be necessary to turn pmode-generated commands into matlabpool + spmd commands.
  • Example — Solving a Linear Algebraic System of Equations

    n = 3;                           % define matrix size
    M = rand(n,n,codistributor());   % create distributed random number matrix
    A = M+M';                        % A = M*M' is a real, symmetric matrix
    x = [1:n]';                      % the solution column vector x
    x = codistributed(x,'convert');  % distribute x among labs
    b = A*x;                         % b = Ax is the right-hand-side
    x2 = Ab;                         % solves for x2
    whos                             % whos shows that all arrays are distributed
    [V, D] = eig(A);                 % find eigen values of real, symmetric matrix