Main Content

参数扫描期间的情节par

此示例显示如何在并行计算期间并行执行参数扫描并绘制进度。你可以使用一个达图在并行池的计算期间监视结果。你也可以使用一个达图具有并行语言功能,如parParfeval.andSPMD.

The example shows how to perform a parameter sweep on a classical system, the Van der Pol oscillator. This system can be expressed as a set of ODEs dependent on the two Van der Pol oscillator parameters, μ and ν

X ˙ = ν y

y ˙ = μ 1 - X 2 的) y - X

您可以在参数上执行并行参数扫描 μ and ν 用一个par循环找出平均时期 y when varying them. The following animation shows an execution of this example in a local cluster.

设置参数扫描值

定义要探索参数的值范围。创建网格格格格以解释参数的不同组合。

gridsize = 6;mu = linspace(100,150,gridsize);nu = linspace(0.5,2,gridsize);[m,n] = meshgrid(mu,nu);

Prepare a Surface Plot to Visualize the Results

声明一个变量来存储扫描结果。采用用于预先放置,以避免绘制初始表面。创建一个表面图以可视化扫描结果的每个组合的扫描结果。准备标题,标签和限制等设置。

Z = nan(size(N)); c = surf(M, N, Z); xlabel('\ mu值''Interpreter''Tex'的)ylabel('\ nu值''Interpreter''Tex')Zlabel('y y')视图(137,30)轴([100 150 0.5 2 0 500]);

在参数扫描期间设置数据线以获取结果

创建一个达图to send intermediate results from the workers to the client. Use theafter在客户端中定义回调的功能,每次工作时间发送当前结果时会更新表面。

d = parallel.pool.dataqueue;d.Aftereach(@(x)更新(c,x));

执行参数扫描和绘图结果

采用par执行并行参数扫描。指示工人解决MeshGrid中参数的每个组合的系统,并计算平均周期。当工作人员完成计算时立即将每个迭代的结果发送回客户端。

parII = 1:NUMER(n)[t,y] =求解vdp(m(ii),n(ii));l = islocalmax(y(:,2));发送(d,[II平均值(差异(t(l))]);结尾
使用“本地”配置文件启动并行池(Parpool)连接到并行池(工人数:6)。

扩展到群集

如果您可以访问群集,可以扩展您的计算。要执行此操作,请删除上一个parpool.那and open a new one using the profile for your larger cluster. The code below shows a cluster profile named'myclusterinthecloud'。要自己运行此代码,您必须更换'myclusterinthecloud'with the name of your cluster profile. Adjust the number of workers. The example shows 4 workers. Increase the size of the overall computation by increasing the size of the grid.

gridsize = 25;删除(GCP('noicreate'));Parpool('myclusterinthecloud',4);
Starting parallel pool (parpool) using the 'MyClusterInTheCloud' profile ... Connected to the parallel pool (number of workers: 4).

如果在设置群集配置文件后再次运行参数扫描代码,则在群集中的工人将在可用时计算并将结果发送到MATLAB客户端。以下动画显示在群集中执行此示例。

辅助功能

创建帮助函数以定义方程式系统,并在其上应用求解器。

function[t,y] = optionvdp(mu,nu)f = @(〜,y)[nu * y(2);mu *(1-y(1)^ 2)* y(2)-y(1)];[t,y] = ode23s(f,[020 * mu],[2; 0]);结尾

声明DataQueue的函数以更新图表的结果来自工人的结果。

functionupdateSurface(s, d) s.ZData(d(1)) = d(2); drawnow('limitrate');结尾

也可以看看