MATLAB parfor-无法确定是否"ModelUtil"是指函数还是变量? [英] MATLAB parfor - cannot determine whether "ModelUtil" refers to a function or variable?

查看:667
本文介绍了MATLAB parfor-无法确定是否"ModelUtil"是指函数还是变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在parfor循环中按如下方式调用外部函数.

I am calling external functions in my parfor loop as follows.

parfor idx = 1:2
    import com.comsol.model.*
    import com.comsol.model.util.*

    model = ModelUtil.create('Model');
    model.modelNode.create('comp1');

    model.geom.create('geom1', 2);
    model.geom('geom1').feature.create('sq1', 'Square');
    model.geom('geom1').feature('sq1').set('size', '0.03125');
    model.geom('geom1').feature('sq1').setIndex('pos', '0', 0);
    model.geom('geom1').feature('sq1').setIndex('pos', '0', 1);
    model.geom('geom1').run;
end

Error: MATLAB cannot determine whether "ModelUtil" refers to a function or variable.
See Parallel for Loops in MATLAB, "Unambiguous Variable Names".

在阅读 MATLAB parfor文档中的明确变量名"部分之后,我几乎理解为什么会发生此错误.但是,我不知道如何解决它.

After reading the "Unambiguous Variable Names" part in the MATLAB parfor documentation, I pretty much understand why this error occurs. However, I have no idea how to fix it.

推荐答案

.Net对象遇到相同的问题.像您一样,我发现它可以在非并行模式下完美运行,而问题仅在parfor时出现.

I encountered the same problem with .Net objects. Like you, I found it works perfectly in non-parallel mode and the problem only occurs with parfor.

这不是路径问题,这纯粹是Matlab语法/解析器问题.

This is not a question of paths, this is purely a Matlab syntax/parser problem.

作为一种解决方法,我将这些操作包装在单独的Matlab函数中,以便在parfor的范围内不再歧义.在该函数中(否则是不必要的),即使从parfor中调用该类,也没有问题的解决.

As a workaround, I wrapped the operations in a separate Matlab function so that within the scope of the parfor it is no longer ambiguous. Within the (otherwise unnecessary) function it has no trouble resolving the class, even when called from within parfor.

这篇关于MATLAB parfor-无法确定是否"ModelUtil"是指函数还是变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆