Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
faq:how_can_i_combine_fieldtrip_with_peer_distributed_computing [2010/12/02 23:01]
128.138.223.50
faq:how_can_i_combine_fieldtrip_with_peer_distributed_computing [2017/08/17 11:21] (current)
Line 42: Line 42:
 ==== Example: processing the MEG data for all tutorial subjects ==== ==== Example: processing the MEG data for all tutorial subjects ====
  
-The MEG data used in the FieldTrip tutorials is available from ftp://ftp.fcdonders.nl/​pub/​fieldtrip/​tutorial/​. There is data for four subjects, which can be processed in parallel as follows. ​+The MEG data used in the FieldTrip tutorials is available from ftp://ftp.fieldtriptoolbox.org/​pub/​fieldtrip/​tutorial/​. There is data for four subjects, which can be processed in parallel as follows. ​
  
-<​code>​+<​code ​matlab>
 subj  = [1 2 3 4]; subj  = [1 2 3 4];
  
Line 51: Line 51:
 for i=1:​length(subj) for i=1:​length(subj)
  
-  % just like in the scripting tutorial, you may want to evaluate a subject specific script that contains +  % just like in the scripting tutorial, you may want to evaluate a  
-  % details such as the filename of the MRI, the location of the raw data or the list of bad channels ​+  % subject specific script that contains details such as the filename ​ 
 +  % of the MRI, the location of the raw data or the list of bad channels ​
   %   %
   % eval(sprintf('​subject%02d_details',​ i));   % eval(sprintf('​subject%02d_details',​ i));
Line 82: Line 83:
 % load the raw data from disk, average it and save the result % load the raw data from disk, average it and save the result
 peercellfun(@ft_timelockanalysis,​ cfg); peercellfun(@ft_timelockanalysis,​ cfg);
- 
  
 </​code>​ </​code>​
Line 90: Line 90:
   chmod 777 ~/public   chmod 777 ~/public
 for the cfg.outputfile and cfg.inputfile options, you should be fine.  for the cfg.outputfile and cfg.inputfile options, you should be fine. 
 +
 +==== Bundling multiple functions in a single distributed job ====
 +
 +If you don't want each function to read/write the intermediate files from/to disk, you can also bundle them into a function that executes them in sequence. For example ​
 +
 +<code matlab>
 +function [source] = preproc_freq_source(cfg1,​ cfg2, cfg3)
 +data = ft_preprocessing(cfg1);​
 +freq = ft_freqanalysis(cfg2,​ data); ​
 +clear data % remove it from memory as soon as it is not needed any more
 +source = ft_sourceanalysis(cfg3,​ freq);
 +clear freq % remove it from memory as soon as it is not needed any more
 +</​code>​
 +
 +And then you would call it in parallel for many subjects and conditions like this
 +
 +<code matlab>
 +for subj=1:10
 +for cond=1:4
 +
 +% here you would specify a different dataset for each subject
 +% and perhaps a different trigger code
 +cfg1{subj, cond} = ...  ​
 +
 +cfg2{subj, cond} = ...
 +
 +cfg3{subj, cond} = ...
 +
 +end % cond
 +end % subj
 +
 +sourceall = peercellfun(@preproc_freq_source,​ cfg1, cfg2, cfg3);
 +</​code>​
 +
 +Here all the source reconstructions will be returned to the master MATLAB session. Of course you can also save them to disk using unique filenames for each subject and condition. Alternatively you can use the cfg.inputfile option for the first step in your bundle of FieldTrip functions, and cfg.outputfile in the last step.
  
 ==== Effective distribution of jobs ==== ==== Effective distribution of jobs ====