473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Memory handling problem

6
Hello
I am using a subroutine to solve relatively large matrix in C++
but I got an error with this text
"The exception unknown software exception (0x0000005) occurred in the application at location 0x0040a97a"

I know that this is an error in memory allocation. my computer has 16GB RAM memory. but I dont know how to use it to solve a matrix greater than 10000x10000.
right now I can not solve matrices greater than 4000x4000.

I appreciate anyone help me

Thanks
Reza
Jan 4 '08 #1
10 1858
gpraghuram
1,275 Expert 1GB
Hello
I am using a subroutine to solve relatively large matrix in C++
but I got an error with this text
"The exception unknown software exception (0x0000005) occurred in the application at location 0x0040a97a"

I know that this is an error in memory allocation. my computer has 16GB RAM memory. but I dont know how to use it to solve a matrix greater than 10000x10000.
right now I can not solve matrices greater than 4000x4000.

I appreciate anyone help me

Thanks
Reza

Are you allocating memory for this statically or dynamically?

Raghuram
Jan 4 '08 #2
Reza2
6
Are you allocating memory for this statically or dynamically?

Raghuram
I am allocating memory dynamically by pointers.
Jan 4 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Let's see your allocation.

And what operating system are you using??

And what compiler??
Jan 4 '08 #4
Reza2
6
the operating system is windows xp and compiler is C++
is there any way that I specify the amount of memory which should be used?
I mean because my computer has 16 GB RAM but I am sure that I am not using it.

thanks
Jan 4 '08 #5
Savage
1,764 Expert 1GB
the operating system is windows xp and compiler is C++
is there any way that I specify the amount of memory which should be used?
I mean because my computer has 16 GB RAM but I am sure that I am not using it.

thanks
Windows Xp can't make use of that RAM amount,maximum it can use is 3.5GB.You will need to install Windows Vista x64(Win Xp x64 for some reason also only uses 3.5GB of RAM).

Also how are you solving those matrices,with recursion?
If so it's no wonder you couldn't solve matrix that big.It takes a lot of space even if you make every entry to be a 1B char.

Savage
Jan 4 '08 #6
Reza2
6
I am using LU decomposition to solve it.
the operating system is xp 64.

is there any way to make the program to work?
Jan 4 '08 #7
weaknessforcats
9,208 Expert Mod 8TB
Reza2: You still haven't shown me your code for your allocation.

The memory you allocate has nothing to do woth the memory in your computer. Check out the section on Memory Management in Windows via C/C++ by Jeffrey Richter 2008.
Jan 5 '08 #8
Reza2
6
I have attached the solver part of my code.
you can see its error.
matrix size is 10000x1000.

#include<math.h>
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include <iomanip.h>
#include <stdio.h>
#include <time.h>
#include <malloc.h>
#include <stdio.h>
#include <math.h>







//************* INPUT Data ************************************************** ******************

const int Nx=100; // no. of fine scale grid in x direction
const int Ny=100; // no. of fine scale grid in y direction


//************************** Variables Arrays *****************************************

double **a,**l,**u,*b,*x;


int i,j,k,n;

//***************************** Subroutines and Functions *************************************/
void linbcg(unsigned long n, double b[], double x[], int itol, double tol,
int itmax, int *iter, double *err);


void solver(double **a,double **u,double **l, double *b,int n,int N); // Solver subroutine
int min(int r,int s); //
int max(int r,int s);





void main()
{






//******************** Matrix Decleration ************************************************** ****


n=Nx*Ny;

b=new double [n+1];
x=new double [n+1];

a=new double *[n+1];
l=new double *[n+1];
u=new double *[n+1];



for(i=0;i<=n;i++){
a[i]=new double [n+1];
l[i]=new double [n+1];
u[i]=new double [n+1];
}






//********* a[][]***************** adjacency matrix
for(j=1;j<=n;j++)
for(i=1;i<=n;i++)
a[i][j]=0.0;

j=1;
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k]=4.9;
}

for(j=2;j<Ny;j++)
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k]=5;
}

j=Ny;
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k]=4.9;
}


for(j=1;j<=Ny;j++)
for(i=1;i<Nx;i++){
k=Nx*(j-1)+i;
a[k][k+1]=2.2;
}


for(j=1;j<=Ny;j++)
for(i=2;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k-1]=2.2;
}

for(j=1;j<=Ny-1;j++)
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k+Nx]= 2.4;
}

for(j=2;j<=Ny;j++)
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
a[k][k-Nx]=2.4;
}





ofstream matrixA("A.dat",ios::in);

for (j=1;j<=n;j++)
{
for (i=1;i<=n;i++)
{
matrixA<<a[i][j]<<" \t";
}
matrixA<<"\n";

}


//********************b[]********** Forcing function matrix ****************************

for(j=1;j<=Ny;j++)
for(i=1;i<=Nx;i++){
k=Nx*(j-1)+i;
b[k]=(0.0);
}

i=1;
for(j=1;j<=Ny;j++)
{
k=Nx*(j-1)+1;
b[k]= 6;

}


i=Nx;
for(j=1;j<=Ny;j++)
{
k=Nx*(j-1)+Nx;
b[k]= 1;

}




//********** solver *********************************************

solver(a,u,l,b,n,Nx);
for(j=1;j<=Ny;j++)
for(i=1;i<=Nx;i++)
{
k=Nx*(j-1)+i;
x[k]=b[k];
}




for(j=1;j<=Ny;j++)
for(i=1;i<=Nx;i++)
{
k=Nx*(j-1)+i;
cout<<"x("<<k<<","<<i<<","<<j<<"]="<<x[k]<<endl;
}

}
//************************************************** ***********************************************

//*********************** subroutin Matrix solver ***************************************
void solver(double **a,double **u,double **l, double *b,int n,int N)
{
int i,j,k,mi,mx;
double zig,sig;
int p=N+1; int q=N+1;


//******* LU decomposition *********************
for(k=1;k<=n-1;k++){
mi=min(k+p,n);
for(i=k+1;i<=mi;i++)
a[i][k]=a[i][k]/a[k][k];
for(i=k+1;i<=mi;i++){
mi=min(k+q,n);
for(j=k+1;j<=mi;j++)
a[i][j]=a[i][j]-a[i][k]*a[k][j];
}
}

for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
l[i][j]=0.0;
u[i][j]=0.0;
}

/// matrix L[][] ////

for(i=1;i<=n;i++){
for(j=1;j<i;j++)
l[i][j]=a[i][j];
}

//////matrix U[][] //////////////

for(i=1;i<=n;i++){
for(j=i;j<=n;j++)
u[i][j]=a[i][j];
}

///// overwriting b[] for L[][] matrix

for(i=1;i<=n;i++){
mx=max(1,i-p);
zig=0.0;
for(j=mx;j<=i-1;j++)
zig=zig+l[i][j]*b[j];
b[i]=b[i]-zig;
}

/// solution matrix x[] for UX=Y

for(i=n;i>=1;i--){
mi=min(i+q,n);
sig=0.0;
for(j=i+1;j<=mi;j++)
sig=sig+u[i][j]*b[j];
b[i]=(b[i]-sig)/u[i][i];
}

}

int min(int r,int s){
int mini=0;
mini=r;
if(s<r) mini=s;
return mini ;
}
int max(int r,int s){
int mxi=0;
mxi=r;
if(s>r) mxi=s;
return mxi;
}

if you know how can I debug it just let me know.
Thanks
Jan 7 '08 #9
Savage
1,764 Expert 1GB
Are you freeing this memory?

Savage
Jan 7 '08 #10
Reza2
6
Not actually.
because it has the problem from the beginning.
Are you freeing this memory?

Savage
Jan 8 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: lawrence | last post by:
I'm not sure how this is normally done, on a large site, perhaps one running Phorum. Occassionally a thread will have hundreds of entries, perhaps a meg or two worth of data. You won't necessarily...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
5
by: Bikash | last post by:
Hello, I am a specific problem in exception handling. The code snippets is attached below. void f() { char *ptr = new char(20); throw 2; }
5
by: Ian | last post by:
I have and Access 97 DB that prints a report that has many pages, sometime about 800-1000 page, each page contains a colour picture along with text boxes. The pictures are displayed on the...
7
by: boss_bhat | last post by:
Hi all , I am beginner to C programming. I have a defined astructure like the following, and i am using aliases for the different data types in the structure, typedef struct _NAME_INFO {...
3
by: Giovanni Boschi | last post by:
We have found a memory leak when using a COM library with a C# application. The leak appears only if the C# application is compiled with the /optimize flag. It goes away when the C# application is...
15
by: syang8 | last post by:
hi, folks, I use Kdevelop to build some scientific simulation on Linux. If I set the size of an array N = 8000, the program works fine. However, if I set the array N some number greater than...
17
by: frederic.pica | last post by:
Greets, I've some troubles getting my memory freed by python, how can I force it to release the memory ? I've tried del and gc.collect() with no success. Here is a code sample, parsing an XML...
27
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.