Parallel MATLAB and Logging

I am running an experiment distributed across multiple computers using the Parallel toolbar. I want to be able to create a log about the progress of the experiment (or any error) and save this information in a file while the processes are running. What is the standard way to do this?

EDIT:

  • I use an awkward parallel.
  • I want only one file for all workers (I have a network drive that can be accessed from the whole machine)

My main concern is to open the file for adding by several employees. Can I lose messages or get an error message?

+3
source share
2 answers

, , . (, C), , MATLAB, , . , ...

, - ( "" ), "master" (.. "" ) .

, , . , MATLAB. , (process_fcn) :

  • "master" . ( labindex process_fcn:

    if (labindex == 1),
      fid = fopen('log.txt','at');  %# Open text file for appending
    end
    
  • , , , data​​strong > , . , try-catch , .

  • process_fcn ( , ), , (.. ), "" . "" . , ( labBarrier, labProbe, labSend labReceive):

    labBarrier;  %# All processes are synchronized here
    if (labindex == 1),  %# This is done by the "master"
      if ~isempty(data),
        fprintf(fid,'%s\n',data);  %# Print "master" data
      end
      pause(1);  %# Wait a moment for "slaves" to send messages
      while labProbe,  %# Loop while messages are available
        data = labReceive;  %# Get data from "slaves"
        fprintf(fid,'%s\n',data);
      end
    else  %# This is done by the "slaves"
      if ~isempty(data),
        labSend(data,1);  %# Send data to the "master"
      end
    end
    data = '';  %# Clear data
    

    PAUSE , labSend "" , "" .

  • , "master" . process_fcn:

    if (labindex == 1),
      fclose(fid);
    end
    
+4

, ( ) , , taskFinish.

- , MATLAB, , .

+2

Source: https://habr.com/ru/post/1711751/


All Articles