Runtime request

Apr 14, 2013 at 9:07am
Hallo.

I have made a neural network model, which, using input data, trains and returns weights of network. I have tested it and it is working correct. But, if i run it like 1000000 times, then, after a while, i get a message, saying, "this application has requested the runtime to terminate it in unusual way. please contact applications support team for more information" and i dont get any results. I dont uderstand whats the problem. If it works correctly, then why there are problems in executing it many times? And i really will need to execute it for many times. I am using dev c++.

Thanks in advance.
Apr 14, 2013 at 11:08am
It's impossible to say what is the problem without seeing the code. But some guesses might be that the program is accessing memory outside the bounds of an array, or dereferencing a pointer after it has been deleted, or maybe there is a memory leak, where memory is not properly released.

If it works correctly, then why there are problems in executing it many times?

You might re-word this as, "If it gives the illusion of working correctly". By definition, if the program has problems, it does not work correctly.

I'd recommend that you share your code here for someone else to take a look at it.
Last edited on Apr 14, 2013 at 11:52am
Apr 14, 2013 at 2:34pm
Thanks for a reply. Ok, here is the code. Hope it will help you to help me.

functions.h
1
2
3
4
5
6
using namespace std;

float **percept(float **x,float *d,int SampleSize,int FactorDim,int MaxEpochs,float MaxError);
float *ArraySum(float *x1,float *x2,int l);
float *ArrayMultiply(float *x,float a,int l);
float ArrayProd(float *x1,float *x2,int l); 


functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include "functions.h"

using namespace std;

float *ArraySum(float *x1,float *x2,int l)
       {
        float *y = new float[l];
        for (int i = 0;i < l;i++)
            y[i] = x1[i] + x2[i];
            
        return y;
       }
  
float ArrayProd(float *x1,float *x2,int l)
       {
        float s =0;
        for (int i = 0;i < l;i++)
            s = s + x1[i]*x2[i];
            
        return s;
       }

float *ArrayMultiply(float *x,float a,int l)
     {
      float *m = new float[l];
      for (int i = 0;i < l;i++)
          {
           m[i] = x[i]*a;
          }
      return m;
     }

float sgn(float x)
       {
        if (x < 0)
           return (-1);
        else if (x > 0)
             return (1);
        else
            return(0);
       }
     
 
 float **percept(float **x,float *d,int SampleSize,int FactorDim,int MaxEpochs,float MaxError)
       {
        float e;
        float E = 100;
        int epochs = 0;
        float *w = new float[FactorDim];
        for (int i = 0;i < FactorDim;i++)
            w[i] = 0;
        
        while (epochs < MaxEpochs && E > MaxError)
              {
               epochs++;
               E = 0;
               for (int i = 0;i < SampleSize;i++)
                   {
                    e = d[i] - sgn(ArrayProd(x[i],w,FactorDim));
                    E = E + 0.5*e*e;
                    w = ArraySum(ArrayMultiply(x[i],e,FactorDim),w,FactorDim);
                   }
               E = E/SampleSize;
              }    
        float **r = new float*[2];
        r[0] = new float[FactorDim];
        r[1] = new float[2];
        r[0] = w;
        r[1][0] = E;
        r[1][1] = epochs;
        return(r);
       }  


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include "functions.h"
using namespace std;


int main()
{
float *d = new float[4];

d[0] = 1;d[1] = -1;d[2] = -1;d[3] = -1;

float **x = new float*[4];
for (int i = 0;i < 4;i++)
    x[i] = new float[3];

x[0][0] = 1;x[0][1] = 1;x[0][2] = 1;
x[1][0] = 1;x[1][1] = 1;x[1][2] = 0;
x[2][0] = 1;x[2][1] = 0;x[2][2] = 1;
x[3][0] = 1;x[3][1] = 0;x[3][2] = 0;


float **w;
w = percept(x,d,4,3,20,0);//calling it one time is ok

for (int i = 0;i < 3;i++)
    cout<<w[0][i]<<",";
    
for (int i = 0;i < 10000;i++)
    w = percept(x,d,4,3,20,0);//even here all is fine

for (int i = 0;i < 3;i++)
    cout<<w[0][i]<<",";

for (int i = 0;i < 10000000;i++)//here are the problems
    w = percept(x,d,4,3,20,0);    


return 0;
}


I guess you are right about program giving me illusion of working correctly. I just couldn't imagine that function, that is working correct one ore even 1000 times woud not work 1000000 times.
Last edited on Apr 14, 2013 at 2:38pm
Apr 14, 2013 at 4:27pm
So far, I only had a quick look, so don't regard this as a definitive statement. The program requires a huge amount of memory, it may simply be requesting more memory than is available on your machine.

One of the warning signs from what I see so far is the use of the new operator to allocate memory, but without any corresponding delete, thus the memory usage can only increase as the program executes, but never go back down.
Apr 14, 2013 at 7:12pm
Thanks again for your replay. Yes, maybe thease problems are duo to the fact, that i dont use delete operator. Maybe after a while there is no memory and the program stops. But there is no way i can delete inside functions, becouse thet need smth to be returned. I guess i'll have to rewrite all functions as void() so it won't be using so much memory and see how it works out. Here i posted a simple example, but data i will have to deal with will usually be 500 X 10 arrays or even bigger, so i guess memory requirements will be big. Anyway, thanks again for spending your time and trying to help me.
Apr 14, 2013 at 8:32pm
Try to use `std::valarray'
Apr 15, 2013 at 6:57pm
The program requires a huge amount of memory, it may simply be requesting more memory than is available on your machine.


It was the problem. I rewrote all functions as voids and used delete everywhere, and now all is working just as i wanted.
Topic archived. No new replies allowed.