How to initialize and load MCR

痞子三分冷 提交于 2019-12-23 16:43:38

问题


I incorporated C++ shared library generated from MATLAB in a Win32 console application. The MATLAB program takes 2-3 sec to execute in MATLAB but the console application takes 11-12 seconds to execute. I read this is because of the start up time of MCR and I believe after the MCR is initialized it must take same time as it takes in matlab. So how can I load or initialize the MCR so that it is always in the RAM or cache so that it will take 2-3 sec for the console application to run? Should I have to make an infinity loop so that the MCR is loaded continously?? I am working on Windows OS and I am calling the console application from PHP. Any tutorials or link for that?

I have added the MCR_CACHE_ROOT as an environment variable which points to a folder(not temporary). My console application code is as follows:

// shoes_shared.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"



using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    /* Call the MCR and library initialization functions */
 //const char *pStrings[]={"-nojvm","-nojit"};
 //   if (!mclInitializeApplication(pStrings,2))
 //   {
 //       fprintf(stderr, "Could not initialize MCR for the application.\n");
 //       return -1;
 //   }

if (!shoes_sharedlibraryInitialize())
{

    exit(1);
}



     mwArray img(argv[1]); 

     double wt1 = _tstof(argv[2]);
     mwArray C(wt1);
    double wt2 = _tstof(argv[3]);
    mwArray F(wt2);
    double wt3 = _tstof(argv[4]);
    mwArray T(wt3);
    double wt4 = _tstof(argv[5]);
    mwArray S(wt4);



           test_shoes(img,C,F,T,S);
            //shoes_sharedlibraryTerminate();
            //mclTerminateApplication();
            return 0;
}

I have commented the lines above thinking that it will make it faster but no luck. Any help?


回答1:


Are you running in debug or release? If you are running in debug, try running in release and see if that solves your problem. Are you using Visual Studio? If so, try opening the modules window there you will see a list of loaded dlls. Check and see if your library is being constantly loaded and unloaded, or if it is loaded once and stays loaded.




回答2:


I don't know on which vm matlab is running, but for example the JVM there is Nailgun, a Java server that runs in the backgroud and can be called whenever some java applications need to be executed. I know that Matlab uses Java, but I am not shure wheather your DLL still invokes it. So if it does, that might be the problem.




回答3:


Try to put MCR and all shared library dependencies to RAM drive.

There are lot of ways to create RAM drive. I would suggest to use ImDisk



来源:https://stackoverflow.com/questions/16432630/how-to-initialize-and-load-mcr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!