0

目前我正在执行具有无限while循环的matlab中的单个文件。

loadconfig
while true
   command = meexcel.getGetParams();    
    refkey = command.get('refkey');
    try 
        if isempty(refkey) == false
            str='';
        document=command.get('documentid');

        documentlanguage=command.get('documentlanguage');
        if isempty(document) == false               
            s=loadSpace(filename,documentlanguage);
        end
        opt.Compact=1;          
        [temp1 temp2] = getPar;         
        jsondata=savejson('',temp1,opt);
        m = java.util.HashMap;           
        m.put('results', jsondata);
        meexcel.setGetParams(m,refkey);
    end 
catch err
    m = java.util.HashMap;
    m.put('results','{msg: Error during calculating}');
    m.put('refkey',refkey); 
    meexcel.setGetParams(m,refkey);
    disp(getReport(err));                                               
end

%plotSemantic function
command = meexcel.getPlotSemanticDistance();    
word = command.get('word'); 
try 
    if isempty(word) == false
        str='';
        refkey = command.get('refkey');
        documentlanguage=command.get('documentlanguage');
        if isempty(documentlanguage) == false               
            s=loadSpace(filename,documentlanguage);
        end

        [h out]=plotSemanticDistance(s,word);
        saveas(h,strcat(download_plot_dir,refkey,'.png'))
        result = strcat(download_plot_url,refkey,'.png');               
        m = java.util.HashMap;           
        m.put('results', result);
        meexcel.setPlotSemanticDistance(m,refkey);
    end 
catch err
    m = java.util.HashMap;
    m.put('results','Error during calculating');
    m.put('refkey',refkey); 
    meexcel.setPlotSemanticDistance(m,refkey);
    disp(getReport(err));

    end
end

我如何处理这个文件的并行执行?meexcel.getGetParams() 之类的函数将在可用时检索数据。该文件具有无限循环。

4

1 回答 1

1

您可以使用 Parallel Computing Toolbox 执行parfeval操作。像这样的东西:

queue = rand(1, 10); % simulated data
futures = [];
while ~isempty(queue)
   % Consume item from queue
   item = queue(end);
   queue(end) = [];
   futures = [futures; parfeval(@sqrt, 1, item)];
end
% Block until all futures are complete and fetch
% the results
fetchOutputs(futures);
于 2015-04-13T11:55:39.757 回答