Questions tagged [c++]
For questions about writing C++ computational code or utilizing libraries written with C++.
328
questions
2
votes
0
answers
51
views
Efficiently retrieiving indices from lattice with periodic boundary conditions
This is something I've never thought too much about because it seemed like an unnecessary micro-optimization, but I've come across a situation where this computation is actually the primary bottleneck ...
0
votes
0
answers
60
views
Where should we compute `Energy` and `Trajectory` in this listing?
Suppose, I have the following listing for a barebone MD simulation:
...
1
vote
1
answer
64
views
Computing LJ force from LJ potential, or not?
Lennard-Jones force can be computed in two different ways:
Version #1:
Here, the force computation is a self-contained routine.
...
1
vote
1
answer
102
views
How can I write a unit test for this routine?
The first routine instantiates numAtoms number of atoms and distributes them in a 6*6*6 grid.
The second routine populates the ...
2
votes
2
answers
914
views
Understanding leapfrog integration algorithm
The leapfrog.cpp is an implementation of leapfrog integration algorithm where f() function is being integrated:
leapfrog.cpp
<...
0
votes
1
answer
147
views
How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?
Considering the following COO sparse matrix format, with repeated indices:
...
0
votes
0
answers
84
views
How to use a surface mesh parameterization?
I'm currently playing with the surface mesh parameterizations of the C++ library CGAL.
For a mesh with a boundary, the computed uv-space (parameterization domain) is either a disk or a square, and so ...
1
vote
1
answer
112
views
Can Spectra find eigenvectors and eigenvalues of complex-valued matrices?
I am using Spectra to iteratively solve large-scale eigenvalue problems. I like it because it readily works on windows, and is header-only. I would like to know if it supports complex-valued matrices. ...
1
vote
0
answers
65
views
How can I optimize the solution of linear systems in my Finite Element Method code for solving nonlinear computational mechanics problems?
Currently, I use Eigen3 for linear algebra operations on sparse matrices and either UMFPACK or CHOLMOD from SuiteSparse to solve sparse linear systems. However, as my model grows larger and the need ...
5
votes
1
answer
922
views
Help with Fourier beam propagation method
I am working on implementing the Fourier beam propagation method in C++. I am really more of a programmer than a physicist but I think I have a good understanding of what I am trying to do. Here is ...
0
votes
0
answers
51
views
How best to iterate over three dimensional grid?
My problem is to iterate through $[0.95,1] \times [0.95,1] \times[0.95,1] \in \mathbb{R}^{3}$. Is there a generic way to do this? I was considering rolling it all out and effectively vectorising the ...
1
vote
0
answers
83
views
Resource to learn assembly code
I'm a PhD student in mechanical engineering and I have to perform a lot of simulations for my project. In my lab we use several well-known libraries, from FEM to machine learning. As we're doing ...
0
votes
0
answers
117
views
Numerical integration library interfacing with eigen
I am looking for a numerical integration library like this one. The examples look very appealing but I see that all test functions use very barebones C arrays.
Do you have any recommendations of ...
0
votes
0
answers
104
views
Solving L1 minimization problems in Eigen
I have an $m\times n$ dense matrix $\mathbf{M}$ and wish to solve $\mathbf{M}\mathbf{x} = \mathbf{b}$ via any of the "L1" methods using Eigen. By this I mean I'm happy with using basis ...
-2
votes
1
answer
438
views
How to solve this differential equation using RK4 in C++?
I have been given the following homework question to solve:
I am having trouble writing a RK4 solver in C++ for this ODE. I am also not sure how to plot my solution. Here is my code so far:
...
10
votes
6
answers
1k
views
Where does Python fit into the picture within computational science field?
So I've been debating whether or not I should bother learning Python. From speaking with my professors, Matlab seems to be the common language used in applied mathematics/computational science as far ...
7
votes
3
answers
4k
views
ROOT (CERN C++ Libraries) alternatives
I have been slowly learning C++ and ROOT for over a year now, in order to debug a program made with it.
Now I reached a point where I can really understand that this will never become easier. ...
22
votes
7
answers
4k
views
Analyzing Numerical Error in C++ Function
Suppose that I have a function that takes as input several floating-point values (single or double), does some computation, and produces output floating-point values (also single or double). I am ...
1
vote
3
answers
184
views
Inefficient comparisons of custom data type C++
I've got some code that I need to squeeze every bit of both time and space out of. I'm looking for a better solution to the following problem.
For reasons outside of the scope of this question, I ...
0
votes
1
answer
156
views
Assign and print the results of CHOLMOD package
I am trying to solve a simple working example, a linear system $Ax=b$, where $A$ is sparse SPD and $b$ is dense, using CHOLMOD.
...
3
votes
1
answer
2k
views
MD Simulation: Reference for the Neighbor's List Method
With a rather basic knowledge in C++, I have written my own MD simulation code. Currently, I calculate forces in the most naive way: I go through all the atoms and account for their interactions. This ...
1
vote
1
answer
236
views
What language are best for creating data compression algorithms except for C/C++?
I've been trying to implement data compression algorithms in python, but I just can't get mine as fast as the other algorithms other have made. So I've decided on using C since I've asked people about ...
1
vote
0
answers
111
views
Does cblas_dgemm mutate my input matrices?
I have written a matrix class Matrix<T> for which I have implemented a wrapper function for cblas_dgemm.
...
0
votes
2
answers
369
views
Searching for recent code source for "Parallel scientific computing in C++ and MPI "
I am learning C++ scientific computing with "Parallel scientific computing in C++ and MPI A Seamless Approach to Parallel Algorithms and their Implementation" since it kept coming up a lot ...
-1
votes
1
answer
552
views
How to initialize Eigen C++ parameters within for-loop? [closed]
I am new to Eigen C++ programming. I am trying to create an Rcpp function to call from R. The function takes a list of matrices (Xlst), and two lists of vectors (ylst and smwlst). In each for-loop ...
0
votes
0
answers
87
views
Recursion relations for integrating Gaussian functions
I'm trying to implement a numerical method used in quantum chemistry from scratch. I'm using this paper as a reference. It's also available on Sci-Hub. So, the method requires calculating integrals of ...
0
votes
0
answers
86
views
Book recommendation request: A good C++ based software development book for a computational mathematician
I'm hoping that this type of question is on-topic, and I have put in a little hunting to make sure it isn't a flat out repeat. If it is either of the above, I apologize in advance.
I'm an early career ...
29
votes
10
answers
22k
views
Fast, lightweight C++ tensor library for dimension-agnostic code
I am looking for a C++ tensor library that supports dimension-agnostic code. Specifically, I need to perform operations along each dimension (up to 3), e.g. calculating a weighted sum. The dimensions ...
3
votes
0
answers
180
views
How can I improve this matrix product calculation in OpenCL?
I am trying to compute a matrix-matrix product of N stacked complex double N x N matrices. For simplicity, I assume N = 512. I have written code in C++ parallelized with OMP and using OpenBLAS for the ...
-1
votes
1
answer
241
views
Armadillo BLAS Matrix Multiplication with it transpose. Blas is too slow?
Does someone knows another trick or solution how can I perform matrix multiplication by its transpose?
The current code for 1000 iterations takes too much time for me.
...
0
votes
1
answer
3k
views
Dynamic Sized Identity Matrix in Eigen
I am aware of creating an identity matrix in Eigen if the number of rows and columns are known. How do we create them dynamically when the size is not known? An example would be useful. Thanks.
2
votes
1
answer
550
views
How to use an adaptive step size in boost::odeint
This is a combination of these two previous questions:
How to get ODE solution at specified time points?
Stop integration in odeint with stiff ode
I need to solve the following differential equation ...
0
votes
1
answer
971
views
C++ compilation error on Mac OSX: gsl library not found [closed]
I'm new to C++ programming. This seems a common error but I can't seem to solve: I'm trying to use the gsl library, with no luck: using ...
16
votes
3
answers
2k
views
Why would a computational scientist need to implement their own version of std::complex?
Many of the better-known C++ libraries in computational science such as Eigen, Trilinos, and deal.II use the standard C++ template header library object, ...
5
votes
2
answers
1k
views
Solver suggestion for many small quadratic problems in C++
I have a C++ program/model that in some parts already use IPOPT (with ADOL-C and ColPack) to solve some pretty large nonlinear problems.
Now in another part of the program, I need to solve a large ...
3
votes
2
answers
390
views
Suggestions for open source C++ library for medium scale non-linear solver
I need to find the root of a nonlinear system (which comes out of collocation, so I will change the order to test). I will likely have about 50-300 variables, and the Jacobian is going to be ...
1
vote
0
answers
831
views
Symmetric Matrix in Eigen C++
I am aware of a symmetric matrix type in uBLAS as ublas::symmetric_matrix matrix. Is there an equivalent for this in Eigen library that can be used to construct one or do we need to explicitly check ...
7
votes
1
answer
2k
views
Eigen C++ Library Over 4x Slower than Fortran
I am experimenting with ways to call compiled programs from Python. My primary interest is iterative optimization methods, so I'm testing an implementation of Newton's method to solve a logistic ...
-1
votes
1
answer
230
views
Delaunay triangulation libraries for sets of 3D points CGAL
I need help. Do you know such a library for 3D triangulation - CGAL? How to get from it the order of joining the vertices to enter into your variable? Found nothing on the official site. Thanks!
1
vote
2
answers
166
views
Need software for generating self-avoiding random walks on a tetrahedral lattice
I am looking for FOSS code that can generate self-avoiding random walk trajectories on a tetrahedral lattice. The purpose of the exercise is to create random conformations of model polymer chains that ...
1
vote
2
answers
1k
views
Recommendations for ODE solvers for stiff equations
I'm continuing the research of a former Ph.D. student in my group requiring the solution of a system of ODEs. On a technical note, they wrote:
The system of Boltzmann equations behaves numerically ...
0
votes
2
answers
1k
views
Are C++ and FORTRAN low or high -level programming languages?
In this post, they mentioned that C++ and FORTRAN are low–level programming languages. However, In other references, they consderd these language as a high-level programming languages.
Which one is ...
-1
votes
1
answer
298
views
Can someone help or point me out to C++ source code for a two body orbit simulation using symplectic integration?
I've professional experience with physics simulations and C++ programming, although
I don't have specific experience with astrophysics simulations.
I'm trying to build a two-body evolving system ...
4
votes
0
answers
85
views
Global reconstruction defined elementwise in a-posteriori error estimator
This question is a follow-up of this previous one. In "Error Control for Discontinuous Galerkin Methods for First Order Hyperbolic Problems" by Georgoulis et al., an error estimator is ...
1
vote
1
answer
367
views
Compute 2D numerical double integration with Boost C++ with parameters
I am trying to compute the double Richardson and Wolf integrals for the focusing of a lens with Boost in C++ (using the Gauss Kronrod method).
As a starting point, I used the example presented in this ...
1
vote
0
answers
238
views
Efficient multidimensional numerical integration in R and C++
I'm trying to perform a 4-dimensional numerical integration in R using a function I wrote in C++ code which is then sourced in <...
8
votes
3
answers
8k
views
Should I pass command line arguments to MPI_Init or not?
When writing MPI 3.0 code, should I pass argc and argv to the MPI_Init call or not, and why?
...
2
votes
3
answers
524
views
How to begin writing scientific codes in C++ in Trilinos or PETSC style?
My background: I have taken some courses on numerical analysis during my PhD and read a few books on the topic as well. I mostly work on low Reynolds number fluid mechanics and use boundary element ...
4
votes
2
answers
475
views
Evaluation of real-valued confluent hypergeometric function with specific complex arguments
In my C++ code, I need to evaluate the confluent hypergeometric function ${}_1F_1(a,b;z)$ with complex arguments in a special case. More precisely, I have to compute
$$
e^{-i\phi}{}_1F_1(\ell+1+iZ,2(\...
66
votes
13
answers
48k
views
C++ vs Fortran for HPC
In my computational science PhD program, we are working almost exclusively in C++ and Fortran. It seems like some professors prefer one over the other. I am wondering which one is 'better' or if one ...