异步调用dll
我希望你能遵循这一点。问题到最后。
我有一个 Excel 2003 工作簿,其中包含要在 DOE(实验设计)中使用的值表。此工作表加载(通过 Workbook.Open
)另一个工作簿并填充正确的字段,然后在第二个工作簿中运行计算(通过 Application.Run("backend.xla!calc")< /代码>)。
反过来,计算调用外部 .dll
(编译为 Fortan)并等待其完成(通过 Declare SubCalculate Lib "fortran.dll" (args )
)。每次运行需要 4 分钟。每个 DOE 可能有 7 到 21 次运行。最后,键值将被拉回到第一个工作簿中以显示结果。
请帮我想出一种方法来创建第二个工作簿的多个副本,并让它们同时(不同的 Excel 进程)分别计算(调用相同的 dll,使用不同的参数),以更好地利用 4 核处理器。
或者也许有某种方法可以直接异步调用外部函数。据我了解,Excel 2003 VBA 是单线程的,外部 dll 只能用作单例(我不确定)。
附言。请随意插话,说我几乎坚持顺序风格的计算。没关系,我可以接受。
I hope you can follow this. The question is in the end.
I have an Excel 2003 workbook that contains a table of values to be used in DOE (Design of Experiments). This sheet loads (via Workbook.Open
) another workbook and populates the correct fields and then runs the calculation in the second workbook (via Application.Run("backend.xla!calc")
).
In turn, the calculation calls an external .dll
(compiled Fortan) and waits for it to finish (via Declare Sub Calculate Lib "fortran.dll" (args)
). Each run takes 4 minutes. There might be 7 to 21 runs per DOE. In the end key values are pulled back in the first workbook to display the results.
Please help me think of a way to create multiple copies of the second workbook and have them each calculate ( calling the same dll, with different parameters ) at the same time (different excel process) to utlitize a 4-core processor better.
Or maybe some way to directly call an external function asynchronously. I understand that Excel 2003 VBA is single threaded, and an external dll could only be used as singleton (I am not sure).
PS. Feel free to chime in a say that I am pretty much stuck to sequencial style calculations. Its ok, I can take it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这虽然又快又脏,但你应该明白了。这个概念是创建全新的 Excel 进程并从每个新进程打开工作簿:
我添加了消息框,因为在消息框上单击“确定”后,xl 变量超出范围,新进程将自动终止。如果您从此变量(即
xl.Workbooks.Open
)运行您的Workbooks.Open
方法,它应该可以到达您想要的位置。This is quick and dirty, but you should get the idea. The concept is to create entirely new Excel processes and open the workbook from each new process:
I added the message box because after you click OK on the message box, the xl variable goes out of scope and the new process is automatically killed. If you run your
Workbooks.Open
method off of this variable (ie,xl.Workbooks.Open
) it should get you where you want.