0

I have a weird problem. I have written some MEX/Matlab-functions using C++. On my computer everything works fine. However, using the institute's cluster, the code sometimes simply stops running without any error (a core file is created which says "CPU limit time exceeded"). Unfortunately, on the cluster I cannot really debug my code and I also cannot reproduce the error.

What I do know is, that the error only occurs for very large runs, i.e., when a lot of memory is required. My assumption is therefore that my code has some memoryleaks.

The only real part where I could think of is the following bit:

#include <vector>

using std::vector;

vector<int> createVec(int length) {
    vector<int> out(length);

    for(int i = 0; i < length; ++i)
        out[i] = 2.0 + i; // the real vector is obviously filled different, but it's just simple computations

    return out;
}


void someFunction() {

    int numUser = 5;
    int numStages = 3;
    // do some stuff

    for(int user = 0; user < numUser; ++user) {

        vector< vector<int> > userData(numStages);

        for(int stage = 0; stage < numStages; ++stage) {
            userData[stage] = createVec(42);

            // use the vector for some computations
        }

    }
}

My question now is: Could this bit produce memory leaks or is this save due to RAII (which I would think it is)? Question for the MATLAB-experts: Does this behave any different when run as a mex file?

Thanks

Chris
  • 2,030
  • 1
  • 16
  • 22

0 Answers0