小编Ing*_*ngo的帖子

并行循环内的Matlab引擎

我在一段并行代码中使用多个matlab引擎时遇到了一些麻烦.我可以使用多个引擎成功生成多个引擎,engOpenSingleUse但无法与多个引擎通信(即调用engPutVariable失败).

与往常一样,最小(VS)示例:

#include "stdafx.h"
#include <engine.h>
#include <omp.h>

int _tmain(int argc, _TCHAR* argv[])
{
//First spawn the matlab engine sessions
Engine *m_Engines[2];
for (int i = 0; i < 2; i++)
{
    m_Engines[i] = engOpenSingleUse(NULL, NULL, NULL);
}

//Then spawn the worker threads...
#pragma omp parallel num_threads(2)
{   
    // Allocate an engine to each thread
    int thread_num = omp_get_thread_num();
    Engine *thisEngine = m_Engines[thread_num];

    #pragma omp for
    for (int i = 0; i < 10000; i++)
    { …
Run Code Online (Sandbox Code Playgroud)

c++ matlab openmp matlab-engine

9
推荐指数
1
解决办法
482
查看次数

使用 ifort 构建可执行共享库

有几个关于 SO 的精彩讨论已经涵盖了如何在 Linux 上生成可执行共享库:

在 C/C++ 中,这似乎相对简单;基本上有两个部分:

  1. 通过在库源代码中包含以下.interp内容,向 ELF添加一个部分(因为ld不包括共享库的部分):
    const char interp_section[] __attribute__((section(".interp"))) = "/path/to/dynamic/linker";
  2. 链接时设置适当的入口点,使用 -Wl,-e,entry_point

有谁知道如何使用 Fortran 编写的库来实现这一目标?具体来说,如何将一个.interp部分添加到使用编译的共享库中ifort

fortran shared-libraries intel-fortran

5
推荐指数
1
解决办法
75
查看次数