Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Code consuming lot of RAM (Memory)

Code consuming lot of RAM (Memory)

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancetutorialannouncementcode-review
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

    #include "ESSolver.h"
    using namespace std;

    int maxIt;
    int minVal;
    int maxVal;

    int main(){
    int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
    maxIt = 1000;

    if( function\_eval == 1){
    	minVal = -32; maxVal = 32;
    }
    
    ESSolver es(nVar, mu, lbd, rhoO, rhoS);
    es.function\_eval = function\_eval;
    es.Init();
    es.Optimize();
    
    return 0;
    

    }

    "ESSolver.cpp"

    #include #include #include "ESSolver.h"
    #include using namespace std;

    ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
    {
    muPop.resize(mu);
    muSigma.resize(mu);
    muSigma2.resize(mu);

    for (int i = 0; i < mu; i++) {
        muPop\[i\].resize(nVar);
        muSigma2\[i\].resize(nVar);
    }
    
    lambdaPop.resize(lbd);
    lambdaSigma.resize(lbd);
    lambdaSigma2.resize(lbd);
    
    for (int i = 0; i < lbd; i++) {
        lambdaPop\[i\].resize(nVar);
        lambdaSigma2\[i\].resize(nVar);
    }
    
    mulambdaPop.resize(mu+lbd);
    mulambdaSigma.resize(mu+lbd);
    mulambdaSigma2.resize(mu+lbd);
    
    for (int i = 0; i < mu+lbd; i++) {
        mulambdaPop\[i\].resize(nVar);
        mulambdaSigma2\[i\].resize(nVar);
    }
    
    rhoPop.resize(rhoO);
    rhoSigma.resize(rhoS);
    rhoSigma2.resize(rhoS);
    
    for (int i = 0; i < rhoO; i++) {
        rhoPop\[i\].resize(nVar);
    }
    
    for (int i = 0; i < rhoS; i++) {
        rhoSigma2\[i\].resize(nVar);
    }
    
    return;
    

    }

    ESSolver::~ESSolver(void) {
    return;
    }

    void ESSolver::Init() {
    for (int i = 0; i < mu; i++) {
    for (int j = 0; j < nVar; j++) {
    muPop[i][j] = rand_r(minVal, maxVal);
    }
    }

    if (mutOp == 0) {
        for (int i = 0; i < mu; i++) {
            muSigma\[i\] = rand01\_r();
        }
    }
    else {
    	for (int i = 0; i < mu; i++) {
    	    for (int j = 0; j < nVar; j++) {
    		    muSigma2\[i\]\[j\] = rand01\_r();
    	    }
        }
    } 
    

    }

    void ESSolver::Optimize() {
    int it = 0;
    while (it < maxIt){
    // Manipulating values of
    // muPop, muSigma, muSigma2,
    // lambdaPop, lambdaSigma, lambdaSigma2,
    // mulambdaPop, mulambdaSigma, mulambdaSigma2,

    M Offline
    M Offline
    Manish K Agarwal
    wrote on last edited by
    #2

    seems mostly with vector resize which you are using extensively.

    L 1 Reply Last reply
    0
    • M Manish K Agarwal

      seems mostly with vector resize which you are using extensively.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      But they will be executed only once during constructor call

      M 1 Reply Last reply
      0
      • L Lost User

        But they will be executed only once during constructor call

        M Offline
        M Offline
        Manish K Agarwal
        wrote on last edited by
        #4

        single run takes more than 1 MB

        L 1 Reply Last reply
        0
        • L Lost User

          Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

          #include "ESSolver.h"
          using namespace std;

          int maxIt;
          int minVal;
          int maxVal;

          int main(){
          int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
          maxIt = 1000;

          if( function\_eval == 1){
          	minVal = -32; maxVal = 32;
          }
          
          ESSolver es(nVar, mu, lbd, rhoO, rhoS);
          es.function\_eval = function\_eval;
          es.Init();
          es.Optimize();
          
          return 0;
          

          }

          "ESSolver.cpp"

          #include #include #include "ESSolver.h"
          #include using namespace std;

          ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
          {
          muPop.resize(mu);
          muSigma.resize(mu);
          muSigma2.resize(mu);

          for (int i = 0; i < mu; i++) {
              muPop\[i\].resize(nVar);
              muSigma2\[i\].resize(nVar);
          }
          
          lambdaPop.resize(lbd);
          lambdaSigma.resize(lbd);
          lambdaSigma2.resize(lbd);
          
          for (int i = 0; i < lbd; i++) {
              lambdaPop\[i\].resize(nVar);
              lambdaSigma2\[i\].resize(nVar);
          }
          
          mulambdaPop.resize(mu+lbd);
          mulambdaSigma.resize(mu+lbd);
          mulambdaSigma2.resize(mu+lbd);
          
          for (int i = 0; i < mu+lbd; i++) {
              mulambdaPop\[i\].resize(nVar);
              mulambdaSigma2\[i\].resize(nVar);
          }
          
          rhoPop.resize(rhoO);
          rhoSigma.resize(rhoS);
          rhoSigma2.resize(rhoS);
          
          for (int i = 0; i < rhoO; i++) {
              rhoPop\[i\].resize(nVar);
          }
          
          for (int i = 0; i < rhoS; i++) {
              rhoSigma2\[i\].resize(nVar);
          }
          
          return;
          

          }

          ESSolver::~ESSolver(void) {
          return;
          }

          void ESSolver::Init() {
          for (int i = 0; i < mu; i++) {
          for (int j = 0; j < nVar; j++) {
          muPop[i][j] = rand_r(minVal, maxVal);
          }
          }

          if (mutOp == 0) {
              for (int i = 0; i < mu; i++) {
                  muSigma\[i\] = rand01\_r();
              }
          }
          else {
          	for (int i = 0; i < mu; i++) {
          	    for (int j = 0; j < nVar; j++) {
          		    muSigma2\[i\]\[j\] = rand01\_r();
          	    }
              }
          } 
          

          }

          void ESSolver::Optimize() {
          int it = 0;
          while (it < maxIt){
          // Manipulating values of
          // muPop, muSigma, muSigma2,
          // lambdaPop, lambdaSigma, lambdaSigma2,
          // mulambdaPop, mulambdaSigma, mulambdaSigma2,

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #5

          What do you mean by lot of memory? I think that about 2M are used by the ESSolver instance of your example code.

          L 1 Reply Last reply
          0
          • J Jochen Arndt

            What do you mean by lot of memory? I think that about 2M are used by the ESSolver instance of your example code.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            I don't know my entire ram got full

            J 1 Reply Last reply
            0
            • M Manish K Agarwal

              single run takes more than 1 MB

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              Actual code has threading. When I ran 10 threads independently, my entire ram of 4GB got full.

              1 Reply Last reply
              0
              • L Lost User

                I don't know my entire ram got full

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #8

                It must be somewhere else in your code because I have compiled the example code and it uses 3355 KiB (waiting for input at end of main and checked the process on another shell in Linux).

                1 Reply Last reply
                0
                • L Lost User

                  Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

                  #include "ESSolver.h"
                  using namespace std;

                  int maxIt;
                  int minVal;
                  int maxVal;

                  int main(){
                  int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
                  maxIt = 1000;

                  if( function\_eval == 1){
                  	minVal = -32; maxVal = 32;
                  }
                  
                  ESSolver es(nVar, mu, lbd, rhoO, rhoS);
                  es.function\_eval = function\_eval;
                  es.Init();
                  es.Optimize();
                  
                  return 0;
                  

                  }

                  "ESSolver.cpp"

                  #include #include #include "ESSolver.h"
                  #include using namespace std;

                  ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
                  {
                  muPop.resize(mu);
                  muSigma.resize(mu);
                  muSigma2.resize(mu);

                  for (int i = 0; i < mu; i++) {
                      muPop\[i\].resize(nVar);
                      muSigma2\[i\].resize(nVar);
                  }
                  
                  lambdaPop.resize(lbd);
                  lambdaSigma.resize(lbd);
                  lambdaSigma2.resize(lbd);
                  
                  for (int i = 0; i < lbd; i++) {
                      lambdaPop\[i\].resize(nVar);
                      lambdaSigma2\[i\].resize(nVar);
                  }
                  
                  mulambdaPop.resize(mu+lbd);
                  mulambdaSigma.resize(mu+lbd);
                  mulambdaSigma2.resize(mu+lbd);
                  
                  for (int i = 0; i < mu+lbd; i++) {
                      mulambdaPop\[i\].resize(nVar);
                      mulambdaSigma2\[i\].resize(nVar);
                  }
                  
                  rhoPop.resize(rhoO);
                  rhoSigma.resize(rhoS);
                  rhoSigma2.resize(rhoS);
                  
                  for (int i = 0; i < rhoO; i++) {
                      rhoPop\[i\].resize(nVar);
                  }
                  
                  for (int i = 0; i < rhoS; i++) {
                      rhoSigma2\[i\].resize(nVar);
                  }
                  
                  return;
                  

                  }

                  ESSolver::~ESSolver(void) {
                  return;
                  }

                  void ESSolver::Init() {
                  for (int i = 0; i < mu; i++) {
                  for (int j = 0; j < nVar; j++) {
                  muPop[i][j] = rand_r(minVal, maxVal);
                  }
                  }

                  if (mutOp == 0) {
                      for (int i = 0; i < mu; i++) {
                          muSigma\[i\] = rand01\_r();
                      }
                  }
                  else {
                  	for (int i = 0; i < mu; i++) {
                  	    for (int j = 0; j < nVar; j++) {
                  		    muSigma2\[i\]\[j\] = rand01\_r();
                  	    }
                      }
                  } 
                  

                  }

                  void ESSolver::Optimize() {
                  int it = 0;
                  while (it < maxIt){
                  // Manipulating values of
                  // muPop, muSigma, muSigma2,
                  // lambdaPop, lambdaSigma, lambdaSigma2,
                  // mulambdaPop, mulambdaSigma, mulambdaSigma2,

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #9

                  As already noted, I have compiled and run your code. The result is as expected: It consumes less than 4 MiB of memory. A common case for running out of memory is - besides allocating huge amounts of memory (e.g. many large objects) - assigning newly created instances to pointer member variables without deleting the old instance.

                  1 Reply Last reply
                  0
                  • L Lost User

                    Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

                    #include "ESSolver.h"
                    using namespace std;

                    int maxIt;
                    int minVal;
                    int maxVal;

                    int main(){
                    int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
                    maxIt = 1000;

                    if( function\_eval == 1){
                    	minVal = -32; maxVal = 32;
                    }
                    
                    ESSolver es(nVar, mu, lbd, rhoO, rhoS);
                    es.function\_eval = function\_eval;
                    es.Init();
                    es.Optimize();
                    
                    return 0;
                    

                    }

                    "ESSolver.cpp"

                    #include #include #include "ESSolver.h"
                    #include using namespace std;

                    ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
                    {
                    muPop.resize(mu);
                    muSigma.resize(mu);
                    muSigma2.resize(mu);

                    for (int i = 0; i < mu; i++) {
                        muPop\[i\].resize(nVar);
                        muSigma2\[i\].resize(nVar);
                    }
                    
                    lambdaPop.resize(lbd);
                    lambdaSigma.resize(lbd);
                    lambdaSigma2.resize(lbd);
                    
                    for (int i = 0; i < lbd; i++) {
                        lambdaPop\[i\].resize(nVar);
                        lambdaSigma2\[i\].resize(nVar);
                    }
                    
                    mulambdaPop.resize(mu+lbd);
                    mulambdaSigma.resize(mu+lbd);
                    mulambdaSigma2.resize(mu+lbd);
                    
                    for (int i = 0; i < mu+lbd; i++) {
                        mulambdaPop\[i\].resize(nVar);
                        mulambdaSigma2\[i\].resize(nVar);
                    }
                    
                    rhoPop.resize(rhoO);
                    rhoSigma.resize(rhoS);
                    rhoSigma2.resize(rhoS);
                    
                    for (int i = 0; i < rhoO; i++) {
                        rhoPop\[i\].resize(nVar);
                    }
                    
                    for (int i = 0; i < rhoS; i++) {
                        rhoSigma2\[i\].resize(nVar);
                    }
                    
                    return;
                    

                    }

                    ESSolver::~ESSolver(void) {
                    return;
                    }

                    void ESSolver::Init() {
                    for (int i = 0; i < mu; i++) {
                    for (int j = 0; j < nVar; j++) {
                    muPop[i][j] = rand_r(minVal, maxVal);
                    }
                    }

                    if (mutOp == 0) {
                        for (int i = 0; i < mu; i++) {
                            muSigma\[i\] = rand01\_r();
                        }
                    }
                    else {
                    	for (int i = 0; i < mu; i++) {
                    	    for (int j = 0; j < nVar; j++) {
                    		    muSigma2\[i\]\[j\] = rand01\_r();
                    	    }
                        }
                    } 
                    

                    }

                    void ESSolver::Optimize() {
                    int it = 0;
                    while (it < maxIt){
                    // Manipulating values of
                    // muPop, muSigma, muSigma2,
                    // lambdaPop, lambdaSigma, lambdaSigma2,
                    // mulambdaPop, mulambdaSigma, mulambdaSigma2,

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #10

                    AtineshS wrote:

                    On running it, I have noticed that it consumes lots of RAM (Memory).

                    How are you verifying this?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    L 1 Reply Last reply
                    0
                    • D David Crow

                      AtineshS wrote:

                      On running it, I have noticed that it consumes lots of RAM (Memory).

                      How are you verifying this?

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      By analyzing system monitor in ubuntu

                      D 1 Reply Last reply
                      0
                      • L Lost User

                        By analyzing system monitor in ubuntu

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        If that's anything like Task Manager in Windows, you should not be using it as a "how much RAM is my program using" gauge. Task Manager is showing you the address space that is in use, which has little (to nothing) to do with the amount of that address space your program is actually using. The "memory" numbers are all but completely useless for telling how much of your memory is actually in use. Think of it more as a high-water mark. While you may have made an allocation at one point in time, freeing the blocks does not guarantee the address space numbers will go down. Those blocks are on the free list, still in the address space, but they are available for subsequent allocation.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        1 Reply Last reply
                        0
                        • L Lost User

                          Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

                          #include "ESSolver.h"
                          using namespace std;

                          int maxIt;
                          int minVal;
                          int maxVal;

                          int main(){
                          int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
                          maxIt = 1000;

                          if( function\_eval == 1){
                          	minVal = -32; maxVal = 32;
                          }
                          
                          ESSolver es(nVar, mu, lbd, rhoO, rhoS);
                          es.function\_eval = function\_eval;
                          es.Init();
                          es.Optimize();
                          
                          return 0;
                          

                          }

                          "ESSolver.cpp"

                          #include #include #include "ESSolver.h"
                          #include using namespace std;

                          ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
                          {
                          muPop.resize(mu);
                          muSigma.resize(mu);
                          muSigma2.resize(mu);

                          for (int i = 0; i < mu; i++) {
                              muPop\[i\].resize(nVar);
                              muSigma2\[i\].resize(nVar);
                          }
                          
                          lambdaPop.resize(lbd);
                          lambdaSigma.resize(lbd);
                          lambdaSigma2.resize(lbd);
                          
                          for (int i = 0; i < lbd; i++) {
                              lambdaPop\[i\].resize(nVar);
                              lambdaSigma2\[i\].resize(nVar);
                          }
                          
                          mulambdaPop.resize(mu+lbd);
                          mulambdaSigma.resize(mu+lbd);
                          mulambdaSigma2.resize(mu+lbd);
                          
                          for (int i = 0; i < mu+lbd; i++) {
                              mulambdaPop\[i\].resize(nVar);
                              mulambdaSigma2\[i\].resize(nVar);
                          }
                          
                          rhoPop.resize(rhoO);
                          rhoSigma.resize(rhoS);
                          rhoSigma2.resize(rhoS);
                          
                          for (int i = 0; i < rhoO; i++) {
                              rhoPop\[i\].resize(nVar);
                          }
                          
                          for (int i = 0; i < rhoS; i++) {
                              rhoSigma2\[i\].resize(nVar);
                          }
                          
                          return;
                          

                          }

                          ESSolver::~ESSolver(void) {
                          return;
                          }

                          void ESSolver::Init() {
                          for (int i = 0; i < mu; i++) {
                          for (int j = 0; j < nVar; j++) {
                          muPop[i][j] = rand_r(minVal, maxVal);
                          }
                          }

                          if (mutOp == 0) {
                              for (int i = 0; i < mu; i++) {
                                  muSigma\[i\] = rand01\_r();
                              }
                          }
                          else {
                          	for (int i = 0; i < mu; i++) {
                          	    for (int j = 0; j < nVar; j++) {
                          		    muSigma2\[i\]\[j\] = rand01\_r();
                          	    }
                              }
                          } 
                          

                          }

                          void ESSolver::Optimize() {
                          int it = 0;
                          while (it < maxIt){
                          // Manipulating values of
                          // muPop, muSigma, muSigma2,
                          // lambdaPop, lambdaSigma, lambdaSigma2,
                          // mulambdaPop, mulambdaSigma, mulambdaSigma2,

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          Thanks Everybody for help issue is resolved. Actually, the problem was in other part of the code where huge amount of memory leaking was happening. :-D :-D

                          1 Reply Last reply
                          0
                          • L Lost User

                            Below is the simplified version of the code I am using in my project. On running it, I have noticed that it consumes lots of RAM (Memory). I am not getting why is that happening, can anybody guide me in the right direction. "main.cpp"

                            #include "ESSolver.h"
                            using namespace std;

                            int maxIt;
                            int minVal;
                            int maxVal;

                            int main(){
                            int function_eval = 1, nVar = 500, mu = 15, lbd = 100, rhoO = 2, rhoS = mu;
                            maxIt = 1000;

                            if( function\_eval == 1){
                            	minVal = -32; maxVal = 32;
                            }
                            
                            ESSolver es(nVar, mu, lbd, rhoO, rhoS);
                            es.function\_eval = function\_eval;
                            es.Init();
                            es.Optimize();
                            
                            return 0;
                            

                            }

                            "ESSolver.cpp"

                            #include #include #include "ESSolver.h"
                            #include using namespace std;

                            ESSolver::ESSolver(int _nVar, int _mu, int _lbd, int _rhoO, int _rhoS):nVar(_nVar), mu(_mu), lbd(_lbd), rhoO(_rhoO), rhoS(_rhoS)
                            {
                            muPop.resize(mu);
                            muSigma.resize(mu);
                            muSigma2.resize(mu);

                            for (int i = 0; i < mu; i++) {
                                muPop\[i\].resize(nVar);
                                muSigma2\[i\].resize(nVar);
                            }
                            
                            lambdaPop.resize(lbd);
                            lambdaSigma.resize(lbd);
                            lambdaSigma2.resize(lbd);
                            
                            for (int i = 0; i < lbd; i++) {
                                lambdaPop\[i\].resize(nVar);
                                lambdaSigma2\[i\].resize(nVar);
                            }
                            
                            mulambdaPop.resize(mu+lbd);
                            mulambdaSigma.resize(mu+lbd);
                            mulambdaSigma2.resize(mu+lbd);
                            
                            for (int i = 0; i < mu+lbd; i++) {
                                mulambdaPop\[i\].resize(nVar);
                                mulambdaSigma2\[i\].resize(nVar);
                            }
                            
                            rhoPop.resize(rhoO);
                            rhoSigma.resize(rhoS);
                            rhoSigma2.resize(rhoS);
                            
                            for (int i = 0; i < rhoO; i++) {
                                rhoPop\[i\].resize(nVar);
                            }
                            
                            for (int i = 0; i < rhoS; i++) {
                                rhoSigma2\[i\].resize(nVar);
                            }
                            
                            return;
                            

                            }

                            ESSolver::~ESSolver(void) {
                            return;
                            }

                            void ESSolver::Init() {
                            for (int i = 0; i < mu; i++) {
                            for (int j = 0; j < nVar; j++) {
                            muPop[i][j] = rand_r(minVal, maxVal);
                            }
                            }

                            if (mutOp == 0) {
                                for (int i = 0; i < mu; i++) {
                                    muSigma\[i\] = rand01\_r();
                                }
                            }
                            else {
                            	for (int i = 0; i < mu; i++) {
                            	    for (int j = 0; j < nVar; j++) {
                            		    muSigma2\[i\]\[j\] = rand01\_r();
                            	    }
                                }
                            } 
                            

                            }

                            void ESSolver::Optimize() {
                            int it = 0;
                            while (it < maxIt){
                            // Manipulating values of
                            // muPop, muSigma, muSigma2,
                            // lambdaPop, lambdaSigma, lambdaSigma2,
                            // mulambdaPop, mulambdaSigma, mulambdaSigma2,

                            K Offline
                            K Offline
                            KarstenK
                            wrote on last edited by
                            #14

                            You are using multi dimensional vectors and loops. That are costly operation. Set you loop params (like 500) to a small number to see the difference. :rolleyes:

                            Press F1 for help or google it. Greetings from Germany

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups