Questions tagged [c++]

For questions about writing C++ computational code or utilizing libraries written with C++.

Filter by
Sorted by
Tagged with
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 ...
drjrm3's user avatar
  • 2,119
57 votes
7 answers
22k views

Is it a good idea to use vector<vector<double>> to form a matrix class for high performance scientific computing code?

Is it a good idea to use vector<vector<double>> (using std) to form a matrix class for high performance scientific computing code? If the answer is no. ...
cfdgeek's user avatar
  • 603
30 votes
5 answers
2k views

What features do users need from an MPI C++ interface?

The 3.0 version of the MPI standard formally deleted the C++ interface (it was previously deprecated). While implementations may still support it, features that are new in MPI-3 do not have a C++ ...
Jeff Hammond's user avatar
  • 2,116
29 votes
9 answers
2k views

What is a good way to run parameter studies in C++

The problem I'm currently working on a Finite Element Navier Stokes simulation and I would like to investigate the effects of a variety of parameters. Some parameters are specified in an input file ...
Matija Kecman's user avatar
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 ...
Michael Schlottke-Lakemper's user avatar
28 votes
9 answers
4k views

Modern C++ in scientific computing?

I am looking for books or articles, or blog-posts, or any published material in general, that address specifically the uses of C++ modern features (move semantics, the STL, iterators, lazy evaluation, ...
a06e's user avatar
  • 1,729
25 votes
5 answers
6k views

What language should I use when teaching an undergraduate course in computer programming?

Going to teach students of undergraduate level a course titled Introduction to Computer Programming. I am confused a bit. In Computational Physics scientists use C/C++ or Python or Fortran,CUDA etc.......
Afnan Bashir's user avatar
25 votes
4 answers
3k views

When should I use C++ expression templates in computational science, and when should I *not* use them?

Suppose that I'm working on a scientific code in C++. In a recent discussion with a colleague, it was argued that expression templates could be a really bad thing, potentially making software ...
Geoff Oxberry's user avatar
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 ...
user_123abc's user avatar
19 votes
6 answers
3k views

To what extent is generic and meta-programming using C++ templates useful in computational science?

The C++ language provides generic programming and metaprogramming through templates. These techniques have found their way into many large-scale scientific computing packages (e.g., MPQC, LAMMPS, CGAL,...
Deathbreath's user avatar
  • 1,042
19 votes
3 answers
11k views

C++ Best practices for dealing with many constants, variables in scientific codes

I am developing a code to simulate fluid flow with biological substances present in the flow. This involves the standard Navier-Stokes equations coupled to some additional biological models. There are ...
EssentialAnonymity's user avatar
19 votes
5 answers
3k views

Parallel Scientific Computation Software Development Language?

I want to develop a parallel scientific computation software from scratch. I want some thoughts on which language to start. The program involves reading/writing data to txt files and doing heavy ...
electrique's user avatar
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, ...
Aron Ahmadia's user avatar
  • 6,931
16 votes
2 answers
2k views

Boost::mpi or C MPI for high performance scientific applications?

The thing I dislike most about MPI is dealing with datatypes (i.e. data maps/masks) because they don't fit that nicely with object oriented C++. boost::mpi only ...
gnzlbg's user avatar
  • 1,075
15 votes
2 answers
8k views

solve $xA=b$ for $x$ using LAPACK and BLAS

I am porting an existing code from MATLAB to C++ and have a linear system to solve $xA=b$ (rather than the more typical form $Ax=b$) The matrix $A$ is dense, and of general form, but is no larger ...
NoahR's user avatar
  • 253
14 votes
4 answers
4k views

Looking for Runge-Kutta 8th order in C/C++

I would like to use Runge-Kutta 8th order method (89) in a celestial mechanics / astrodynamics application, written in C++, using a Windows machine. Therefore I wonder if anyone knows a good library / ...
James C's user avatar
  • 277
14 votes
2 answers
510 views

What are new c++20 features that are relevant to scientific computation?

In my research department we plan a small seminar on the new c++20 language standard. There are exhaustive lists online presenting the new features of the language standard, some of which will be of ...
MPIchael's user avatar
  • 2,627
13 votes
5 answers
987 views

Compute $(e^x-1)/x$ near $x = 0$

The function $f \colon x \mapsto (e^x-1)/x$ has singularity near $x = 0$. That singularity can be lifted, though: for $x = 1$, one should have $f(x) = 1$, since $$ e^x = \sum_{k=0} \frac{x^k}{k!} $$ ...
anonymous's user avatar
  • 233
13 votes
3 answers
1k views

Blaze linear algebra library?

The paper "Expression Templates Revisited: A Performance Analysis of Current Methodologies" in SIAM Journal of Scientific Computing references the "Blaze" linear algebra library. I haven't heard of it ...
cjordan1's user avatar
  • 805
12 votes
3 answers
1k views

Efficient tridiagonal matrix algorithm implementation

I am solving a physical problem using implicit numerical scheme. This leads me to solving a linear equation with tridiagonal matrix. I've coded this algorithm from Wikipedia. I wonder if there is an ...
gmk's user avatar
  • 455
12 votes
1 answer
871 views

Replacing Mathematica's QuasiMonteCarlo integration in C++

I have a Mathematica program which performs some integrals in 3 or 4 dimensions using the QuasiMonteCarlo method. The problem is, it takes an annoyingly long time ...
David Z's user avatar
  • 3,373
11 votes
1 answer
11k views

Applying the Runge-Kutta method to second order ODEs

How can I replace the Euler method by Runge-Kutta 4th order to determine the free fall motion in not constant gravitional magnitude (eg. free fall from 10 000 km above ground)? So far I wrote simple ...
Marcin W.'s user avatar
  • 113
11 votes
3 answers
1k views

Testing if two 12x12 matrices have the same determinant

I am given a $12 \times 12$ matrix $Q$ that is symmetric, invertible, positive definite and dense. I need to test if $$\det(Q) = \det(12I-Q-J) \; \; (1)$$ where $J$ is the all ones matrix. I am ...
Jernej's user avatar
  • 458
11 votes
2 answers
17k views

C++ library for nonlinear constrained minimization

I am currently trying to solve nonlinear constrained minimization problem as implemented in matlab "fmincon" function. My expectations are, minimize(fun1,x0,uB,lB,fun2) where x0 is initial state, fun1 ...
Peter Kottas's user avatar
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 ...
TheRealFakeNews's user avatar
10 votes
3 answers
2k 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 ...
Michael's user avatar
  • 1,463
10 votes
3 answers
4k views

How to build a recursive spline function in C++

At the moment I am working on a differential equation solving method called basis-spline collocation. What I am having trouble with is building a method to build an arbitrary order spline, with the ...
Kane's user avatar
  • 101
10 votes
3 answers
3k views

How to use polylogarithm function in c++?

Is there any preprocessor directives that could be used to use the polylog function? Or is it included in cmath? If so, do you call it by Li or by polylog? EDIT: What I really am trying to do is give ...
flamingohats's user avatar
10 votes
1 answer
1k views

How to document math formulations in scientific computing codes?

I am writing the code relate to math. There is some complicated math formulation in the project. Directly writing the calculation code leads to hard understanding; thus I want to comment on the ...
Xu Hui's user avatar
  • 323
10 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 ...
Walter's user avatar
  • 258
10 votes
1 answer
720 views

What is the impact of C++11 move semantics in the context of scientific computing?

C++11 introduces move semantics which can, for example, improve code performance in situations where C++03 would need to perform a copy construction or copy assignment. This article reports that ...
Matija Kecman's user avatar
10 votes
1 answer
3k views

Is using std::valarray considered good practice?

C++ has had the std::valarray class since the C++98 standard. It is meant to facilitate numerical computations, providing the sort of operations one would expect of ...
Wolfgang Bangerth's user avatar
10 votes
0 answers
333 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 ...
H A Helfgott's user avatar
9 votes
6 answers
13k views

Super C++ optimization of matrix multiplication with Armadillo

I'm using Armadillo to do very intensive matrix multiplications with side lengths $2^n$, where $n$ can be up to 20 or even more. I'm using Armadillo with OpenBLAS for matrix multiplication, which ...
The Quantum Physicist's user avatar
9 votes
10 answers
5k views

Is it possible to optimise this integration code so that it runs faster?

...
user2970116's user avatar
9 votes
4 answers
530 views

Hosting site for a small scientific library

For my research work I have been developing a small C++ library aimed at facilitating the communication between C++ computational codes and Octave/Matlab (when the latter is used for post-processing ...
Acorbe's user avatar
  • 313
9 votes
3 answers
2k views

Recommendations for a lightweight/no-install C or C++ based dense linear algebra solver

Most of my programming is one-off research codes in C for my own use. I have never distributed any code to other than close collaborators. I have developed an algorithm that I am publishing in a ...
jep's user avatar
  • 193
9 votes
1 answer
741 views

Implementation of Jacobi-Davidson method for cubic eigenvalue problem

I have a large cubic eigenvalue problem: $$\left(\mathbf{A}_0 + \lambda\mathbf{A}_1 + \lambda^2\mathbf{A}_2 + \lambda^3\mathbf{A}_3\right)\mathbf{x} = 0.$$ I could solve this by converting to a ...
OSE's user avatar
  • 397
9 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: ...
Bociek's user avatar
  • 191
8 votes
9 answers
1k views

Do I need to learn C?

I am a PhD student in Scientific Computing and over the past few months, I spent a good amount of time learning Python and C++ the right way. I feel that I have learnt C++ well and I can use Python to ...
Inquest's user avatar
  • 3,344
8 votes
4 answers
6k views

How to efficiently assemble global stiffness matrix in sparse storage format (c++)

I am writing a finite element solver in C++. The main bottle neck is assembling the global stiffness matrix in sparse compressed row storage (so far I am only solving steady problems). Because I don't ...
James's user avatar
  • 1,879
8 votes
2 answers
9k views

Programming Finite Element Methods in C++

I am trying to develop a library for finite element methods in C++ and for that I am looking at the data structures for meshes. Based on what I've read up on fenics and deal.ii, the general ...
gk1's user avatar
  • 322
8 votes
1 answer
2k views

Why am I getting so much error for my Runge Kutta Fehlberg solver?

My current project is a reprogramming of a protein folding model involving the solution of thousands of ODEs in C++. I've been making some stop and start progress as I'm writing the solver to run ...
Hair of Slytherin's user avatar
8 votes
1 answer
831 views

C++ library for graphs with maximum common subgraph solver

I'm looking for a convenient, free C++ library for graphs that include a solver for the maximum common subgraph (MCS) problem. I'm aware of the Boost Graph Library and LEMON , but neither includes an ...
Deathbreath's user avatar
  • 1,042
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? ...
gnzlbg's user avatar
  • 1,075
8 votes
0 answers
4k views

Good C++ optimization library for BFGS

To implement maximum likelihood estimators, I am looking for a good C++ optimization library that plays nicely with Eigen's matrix objects. Eigen has some capability of interfacing of its own but if ...
Hirek's user avatar
  • 183
7 votes
4 answers
8k views

How to find more than one root of a polynomial?

This program finds the first root of the function f, defined in the code. There are 5 roots of this function. (x=1,2,3,4,5) I wish to find all of the roots in this program and print them to the screen....
flamingohats's user avatar
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. ...
Presbitero's user avatar
7 votes
2 answers
670 views

Recommendations for a usable, fast GPL-compatible derivative-free numerical optimization library that can be interfaced to C++

I am dealing with optimization of functions for which I do not have derivatives available, and the optimization is not constrained. I am searching for a high quality GNU Public License-compatible ...
tmaric's user avatar
  • 1,916
7 votes
2 answers
759 views

transitive floating point comparison with (absolute) tolerance

I want to compare two floating point numbers for equality relative to a known absolute tolerance. However, this is inside an algorithm I wrote quite some time ago, and I believe the logic of that ...
Thomas Klimpel's user avatar

1
2 3 4 5
7