Questions tagged [c++]
For questions about writing C++ computational code or utilizing libraries written with C++.
337 questions
0
votes
1
answer
62
views
Passing in a vector from this particular matrix class floating around online [closed]
I am using this matrix class here to assist me in converting this Least Squares algorithm that prices American options that is written in Matlab in C++. My question is pretty simple. I want to pass in ...
0
votes
1
answer
3k
views
two level iterators C++ [closed]
I am trying to implement a two level iterator as I will now describe. Basically I have a "vector of vectors" and I want a single iterator that will loop over all the objects in the vector of vectors.
...
5
votes
3
answers
3k
views
Efficiently computing the product of a multi-dimensional matrix (or tensor) and vectors
Update: Thank you very much for all of you who answered below. I'm studying each answer now. In the long term, I'm more interested in solutions that work for sparse tensors (sorry I should have ...
6
votes
4
answers
8k
views
Beating typical BLAS libraries matrix multiplication performance
A dull matrix multiplication algorithm where we use the formula
$$C_{ij}=\sum_{k}A_{ik}B_{kj}$$
By literally following this in 3 loops we'll get a very slow program, because we don't utilize ...
10
votes
3
answers
3k
views
Are there any "light-weight" FEM packages around?
Basically, FEM seems to be a problem that is pretty much "solved". There are numerous powerful frameworks existing, like Trilinos, PETSc, FEniCS, Libmesh or MOOSE.
One thing they have in common: They ...
3
votes
2
answers
2k
views
Developing a C++ solid mechanics program
I am a beginner in computational science and programming. I am doing research in non linear solid mechanics analysis and using C++ for coding. I have been exploring various finite element open source ...
2
votes
0
answers
78
views
Under what circumstances does Elemental's distributed SVD not work? [closed]
I am playing around with Elemental's distributed singular value decomposition and am running into two particular issues.
Building the test at tests/lapack_like/SVD.cpp, and running with
...
2
votes
1
answer
696
views
Fast C++ implementation of sparse binary matrices
I am looking for the subject. The size of matrices will be around 1000x2000 elements with linear amount of ones (say, 6000 ones in the whole matrix).
The operations I will use the most:
iterating ...
1
vote
0
answers
706
views
Looking for C++ function for performing optimization of parameters for multivariable function
I am adapting a Java program from C++ and need a C++ function to perform the same task as the Java BOBYQAOptimizer() function. Can anyone recommend a C/C++ library with equivalent or similar functions ...
11
votes
0
answers
355
views
Numerical integration using interval arithmetic, nowadays
Is there now a package for rigorous numerical integration that uses interval arithmetic and has access to a well-developed library of special functions?
By "well-developed", I mean something that, at ...
1
vote
1
answer
2k
views
Eigen - Solving Complex Generalized Eigenvalue Problem
I've been using the Eigen C++ linear algebra library to solve various eigenvalue problems with complex matrices. I've recently had to use a generalized eigenvalue solution process, only to be ...
3
votes
1
answer
2k
views
Vectorize a part of a huge matrix in C++
I have a large matrix, side-length is about $n\geq 1000$. I need to do element-wise multiplication of this matrix with another matrix many, many times. I make this process by:
Vectorizing (through ...
3
votes
1
answer
321
views
Fastest method forfinding a solution to x*log(x)
more specifically, $C x \log_2(x)- K = 0$, where $C$ and $K$ are constants ($\log_2$ means log base 2).
I was solving a topcoder problem, SortEstimate, which requires us to solve the aforementioned ...
5
votes
1
answer
1k
views
Why do libraries need hand-vectorized code instead of compiler auto vectorization
C++ eigen library does vectorization for different architecture, like SSE, NEON etc. In their documentation they mentioned that, Eigen vectorization is not compiler dependent. But most modern ...
2
votes
3
answers
497
views
State of the art in parallel data structures [closed]
I'm currently evaluating how I could implement several algorithms on a parallel computer with a large number of nodes, each also equipped with a powerful GPU. It turns out that for many algorithms, it ...
1
vote
2
answers
1k
views
GSA Search Algorithm in C++
Is there any version of GSA (Gravitational Search Algorithm)[1] implemented with C++ or even C#?
What I found was implemented using MATLAB which is not good for me.
[1] Rashedi, Esmat, Hossein ...
0
votes
1
answer
1k
views
Three body problem in C++
I am in a begginers programming course and we got a little project. I chose to simulate the three body problem using the Euler method. Even though the system is chaotic there are some special cases ...
0
votes
1
answer
3k
views
Equation of motion by RK4 method
I would like to sole the spring mass equation of the form:
$M\ddot{Y}+B\dot{Y}+KY = F_y(t)$, where $M :$ mass, $B :$ Damping, $K : $ stiffness, $F_y :$ external force and $Y :$ displacement in ...
7
votes
2
answers
17k
views
C++ libraries for Fast Fourier Transform in high precision
I am looking for a C++ library for Fast Fourier Transform (FFT) in high precision (e.g., using high precision real data types similar to mpfr_t in MPFR or ...
2
votes
1
answer
1k
views
Complex Numerical Integration using GSL
I want to program an integration routine in C++ using the GSL library but for complex functions.
How should I split my integrand to apply the gsl_integration_qag function on it.
Just integrate the ...
1
vote
4
answers
2k
views
Which C++ Multi-objective Optimization libraries allows the addition of custom problems and custom algorithms?
I'm working on a custom discrete and constrained multi-objective optimization problem and I'd like to know which libraries or platforms that implement algorithms like ...
1
vote
1
answer
561
views
Efficiently rotate vector in 2D (and 3D)
I need to efficiently rotate a 2D (and 3D) vector in a CUDA kernel. I was thinking about generating random unitary rotation matrices. I don't need to know the angle, it just has to be randomly ...
3
votes
2
answers
2k
views
Stabilizing a 3x3 real symmetric matrix eigenvalue calculation
I have many 3x3 real symmetric matrices for which I need to determine the eigenvalues. Wikipedia gives a nice non-iterative algorithm for this case, which I have translated into C++:
...
0
votes
2
answers
265
views
Adaptive numerical integration of a univariate vector integrand
Background & Problem formulation
I'm trying to write a simple program in C++ that performs adaptive numerical integration of vector valued integrands (in one variable), i.e.
$$\int_a^b \bar{f}(...
-2
votes
1
answer
3k
views
How to implement Lagrangian/Polynomial Interpolation for my C++ Code?
I have a working C++ function:
...
5
votes
1
answer
985
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 ...
2
votes
2
answers
1k
views
How does MPI differentiate between two computers?
I am starting to dabble in MPI. I am fairly new to this area and I am currently reading the MPI standard.
I would like to write my first MPI program, a simple hello world program, on a cluster that ...
0
votes
1
answer
4k
views
Inversion of a matrix using c++ library armadillo or eigen [closed]
I'm trying to find inverse of a matrix using c++ library armadillo or eigen. But first row of the matrix is wrong, please note that other elements are correct. I'm unable to understand what mistake I ...
5
votes
2
answers
2k
views
I am searching for a C++ code implementing the complex polygamma function
I googled about some code on the complex polygamma function especially C++ code, but can't find anything. Does anyone know where to find such code?
The complex digamma function does exist but not the ...
0
votes
1
answer
112
views
$LU$ factorization routine to solve system $Lv = f$ and $Uv = f$
I implemented an $LU$ factorization algorithm on c++ for a $n$ by $n$ matrix $A$, and I wanted to now write a routine that solves the systems $Lv = f$ and $Uv = f$. How would you recommend writing ...
-1
votes
2
answers
231
views
$LU$ factorization
Our task is to implement a factorization routine that given A in a suitably efficient data structure returns the factors $L$ and $U$ where $L$ is unit lower triangular and $U$ is upper triangular. In ...
3
votes
2
answers
274
views
FEM libraries with weak forms
I need to implement a structural analysis code, and I turn to you for advice. My needs are simple:
Library must be integrable in a C++ code
I want to express a weak form, without manual intervention
...
-2
votes
1
answer
934
views
Understanding and implementing the Fast Fourier Transform
I need to write the fast fourier transform in C++ and I am referring to this formula from wikipedia:
But for some reason I am not getting the correct output when I simply enter (1,1) (1,1) (1,1) (1,...
1
vote
2
answers
275
views
Programming language for HPC [closed]
I'm planning on building a program that will carry out HPC. I'm aware that C/C++ is significantly better than Python in terms of the speed of computation. However, I'm not yet proficient in C/C++, so ...
0
votes
1
answer
2k
views
Fastest way to diagonalize square matrices with c++
I am currently writing software in c++ which solves the eigenvalue problem of sparse hermitian matrices. The size of the matrix depends on the user input, but as an estimation it will roughly be ...
5
votes
3
answers
1k
views
What do C, C++ and Java have that Fortran 2003 don't? [closed]
As you may know, Fortran is widely and longly (?) used in science. I've heard a lot of people saying that we natural scientists should all migrate to C++ or Java. I've seen people increasingly ...
8
votes
2
answers
1k
views
Library with polylogarithm function [duplicate]
I am looking for a reliable library where I can find polylogarithm function and newton/secant method for solving non-linear equations. Basically I have something like this:
...
2
votes
1
answer
2k
views
Armadillo library appears slow
I have been experimenting in building a C++ project for a FDTDS system for Electro-Magnetics. I have implemented a class [see below] which I called mesh using the Armadillo library. The 3D matrices {...
4
votes
2
answers
487
views
Advice on handling many "small" matrices in parallel
I'm working on a small fun project on the side for a numerical method I've been working a bit with. Roughly, the computational problem I have to solve is the following: Assume you have a collection of ...
2
votes
1
answer
283
views
Topics about the deal.II finite element library class "SparsityPattern"
When learning the deal.II FE library, I am a bit confused about the mechanism of its "SparsityPattern" class. Through reading the documentation, I only got to know that it uses the Compressed Row ...
2
votes
1
answer
4k
views
Solving Linear Equations using Eigen
I am trying to solve linear equations in c++ using the Eigen library. For the simple equation Ax=b, I have a sparse matrix A that is n x n, and known values for b which is n x 1, but I need to find ...
1
vote
1
answer
14k
views
Looking for a C/C++ implementation of the Hungarian method for real-valued cost matrix
I am looking for a C/C++ implementation of the Hungarian method for solving the linear assignment problem with real-valued cost matrix.
Some implementation I found, such as this one, only work for ...
3
votes
0
answers
55
views
Coupled Diff Equation from Bose Einstein distribution
I am a student doing physics hons and have had very little experience in programming. This semester we are supposed to do a computational project in thermodynamics. I have to solve these two coupled ...
4
votes
2
answers
523
views
overflow upper incomplete gamma function
I want to calculate the following equation:
$$\frac{\theta \Gamma \left(\kappa+1,\frac{o}{\theta }\right)-o \Gamma \left(\kappa,\frac{o}{\theta }\right)}{\Gamma (\kappa)}+o+s$$
with $s>0, o>0, ...
1
vote
3
answers
400
views
Traveling Salesman Problem
First off some context. The Traveling Salesman Problem(TSP) is to find the most efficient route passing through a series of points only once. However, there is no perfect function to solve for this in ...
5
votes
2
answers
2k
views
How to implement adaptive mesh refinement using conformal triangles
I am trying to implement adaptive mesh refinement for a finite element code. The code uses (at least for now) linear triangles and so when I do the mesh refinement I want the triangular mesh to remain ...
3
votes
1
answer
774
views
Kernel of a Sparse Matrix
Given a sparse rectangular matrix $A$ (let's say, with dimension $n,m$ and number of non-zero elements $O(n)\sim O(m)$) with entries in $\mathbb Z/2\mathbb Z$ I'm looking for a basis of the kernel as ...
2
votes
2
answers
1k
views
Kummer's confluent hypergeometric for complex arguments in C/C++?
I need to evaluate Kummer's confluent hypergeometric function for imaginary arguments:
$$_1F_1(a,b;ix)$$
where $i$ is the imaginary unit, $a,b,x$ are real, and $a,b>0$. Is there a routine ...
11
votes
5
answers
9k
views
C++ library for numerical intergration (quadrature)
I have my own little subroutine for numerical integration (quadrature), which is a C++ adaptation of an ALGOL program published by Bulirsch & Stoer in 1967 (Numerische Mathematik, 9, 271-278).
I ...
6
votes
1
answer
724
views
Using Log Gamma function to avoid overflow
I have to do some numerical calculus using gamma functions. I am using the tgamma incluided in the C++ cmath library. The ...