Can a Large Matrix Allocation Cause a Windows Error in Circuit Simulation?

In summary, there is a limit to the amount of data you can allocate at one time in C++. The limit is either 32768 or 65536, not 28000. When you reach the limit, the computer segfaults.
  • #1
Phymath
184
0
Hey,

In doing a circuit simulation i want to allocate a matrix like this (c++)

double S1store[3][steps+1]

i get no compiling errors, but if i make steps greater then 28000 the program gives me a windows error and crashes, it runs fine on a unix system. is there a limit to the amount of data you can allocate at one time? (i have 1GB RAM 3.2 Ghz processor) i don't think that would fill up. Or do you think the compiler doesn't complie correctly when your matrix is that large?

thanks for any help, i would have put this is programming but i know there's better programmers in physics lol
 
Physics news on Phys.org
  • #2
There is a limit, it should be either 32768 or 65536 , not 28000. But I'll assume you went from 28000 to 35000 or something, and that's when it crashed. Try changing the steps to be of type "unsigned long int" instead of type "int" that should give you some more room. Unsigned tells the computer not to allow the int to store negative numbers, doubling the number of positive numbers it can hold. Long int tells it to allocate more bits to storage increasing the number of ints it can hold (but sometimes exactly how much it increases depends on the compiler / operating system, which is probably why this is working on *nix and not windows)

~Lyuokdea
 
  • #3
ya thanks a lot its a segmentation fault good idea about the unsigned i already have the long int, i also reduced the matrix to three single arrays

SnstoX[steps], SnstoY[steps],SnstoZ[steps], now I am maxing out at around 149896 = steps. I'm thinking that the program is trying to "point" to memory spots already taken up in the program, as in SnstoX[1] could have the same mem spot as SnstoX[120000] and the computer is obviously segfaulting...im 99.5% positive I am not accessing memory not allocated in the arrays...as in I am not accessing SnstoX[steps] literally but SnstoX[steps-1] which is suposed to be the max, ill try the unsigned thing thanks if you got any more ideas that'd be helpful
 

1. What is computational physics?

Computational physics is a subfield of physics that uses computer simulations and mathematical algorithms to study and solve physical problems. It combines the principles of physics with the power of computers to analyze complex systems and phenomena that may be difficult to study through traditional experimental methods.

2. How is computational physics used in research?

Computational physics is used in research to model and simulate physical systems, such as quantum mechanics, fluid dynamics, and astrophysics. These simulations allow scientists to study complex phenomena and make predictions that can inform and guide experimental research. Computational physics also plays a crucial role in the development and testing of new theories and models.

3. What programming languages are commonly used in computational physics?

The most commonly used programming languages in computational physics are Fortran, C/C++, and Python. Each language has its own strengths and is often chosen based on the specific needs of the simulation or research project. Other languages, such as MATLAB and Julia, are also frequently used in computational physics.

4. What are the benefits of using computational physics?

There are many benefits to using computational physics, including the ability to study complex systems that may be difficult or impossible to study through traditional experimental methods. It also allows for rapid testing and prototyping of new theories and models, as well as the ability to simulate extreme conditions that may not be possible in a laboratory setting. Additionally, computational physics can save time and resources by reducing the need for expensive experimental equipment.

5. What are some real-world applications of computational physics?

Computational physics has a wide range of real-world applications, including weather forecasting, materials science, nuclear energy, and aerospace engineering. It is also used in medical research, such as modeling and simulating the behavior of proteins in drug development. In addition, computational physics plays a critical role in the development and optimization of technologies such as solar cells, batteries, and electronic devices.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
17
Views
2K
Replies
1
Views
790
  • Programming and Computer Science
Replies
4
Views
7K
Replies
3
Views
926
Replies
4
Views
1K
  • Programming and Computer Science
Replies
7
Views
6K
Replies
6
Views
4K
Back
Top