多体素模式识别工具箱(TDT toolbox )如何并行计算?

问题描述

在32核的服务器上运行The decoding toolbox (TDT)。利用searchlight的方法分析,searchlight的数目是140434个。
解码代码如下:

cfg = decoding_describe_data(cfg,{labelname1 labelname2 labelname3 labelname4},[-1.5 -0.5 0.5 1.5],regressor_names,beta_loc);
cfg.decoding.method = ‘regression’; % choose this for regression
cfg.results.output = ‘zcorr’;

如此运行代码将花费数天不止,多模式识别工具箱(TDT toolbox )如何并行计算?

解决方案一

1、明确探照灯的数目n_sl,假设没有并行化处理。假设处理数据利用n_split 个并行迭代。于是可以将不同顺序的探照灯并行处理完成后,将结果进行累加,从而完成加速。

iter = 1;
n_sl = 49000;
n_split = 7;
splitsize = ceil(n_sl/n_split);
cfg.searchlight.subset = (iter-1)*splitsize + (1:splitsize); % would run the first 7k searchlights

根据这个示例,更改不同的iter值,就可以得到不同位置的searchlight结果。然后利用matlab parfor 可以完成整个程序的并行。可参考如下代码进行修改完善:

pool = gcp(‘nocreate’);
num_workers = pool.NumWorkers;
num_searchlights = size(misc.residuals,2);
searchlights_per_worker = ceil(num_searchlights/num_workers); % Divide the task up into the number of workers
parfor crun = 1:num_workers
results{crun} = decoding_parallel_wrapper(cfg,misc,searchlights_per_worker,crun)
end
all_results = results{1};
for crun = 2:num_workers
all_results.decoding_subindex = [all_results.decoding_subindex; results{crun}.decoding_subindex];
all_results.other_average.output(results{crun}.decoding_subindex) = results{crun}.other_average.output(results{crun}.decoding_subindex);
end
results = all_results;
disp(‘Crossnobis on the whole brain complete, saving results, note this could take some time’)
save(fullfile(cfg.results.dir,‘res_other_average.mat’),‘results’,’-v7.3’)
assert(sum(cellfun(@isempty,all_results.other_average.output))==0,‘Results Output not completely filled despite completion of the parallel loop - please check’)
delete(fullfile(cfg.results.dir,‘parallel_loop*.mat’))

其中调用的decoding_parallel_wrapper如下:

function results = decoding_parallel_wrapper(cfg,misc,searchlights_per_worker,worker_number)
cfg.searchlight.subset = ((worker_number-1)searchlights_per_worker)+1:worker_numbersearchlights_per_worker;
cfg.results.resultsname = cellstr([‘parallel_loop_’ num2str(worker_number)]);
addpath /group/language/data/thomascope/spm12_fil_r6906/ % Your SPM path for the workers
spm(‘ver’); % Needed or sometimes the decoding toolbox complains in parallel that SPM is not initialised.
results = decoding(cfg,[],misc);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值