2

I wonder if it is a good idea to initialize an array to zero in C++ as follows:

const int n = 100;
double* x = new double[n];
cblas_dscal(n,0.0,x,1); 

Any ideas?

Flow
  • 22,860
  • 14
  • 95
  • 151
Eissa N.
  • 1,605
  • 10
  • 17

2 Answers2

3

There is no need for an extra call to a mkl function. Just do:

const int n = 100;
double* x = new double[n]();

This is a C++ feature, explained in more detail here.

Community
  • 1
  • 1
Bort
  • 2,321
  • 13
  • 22
1

Better is to use a vector, which lets you specify the initial value as an optional parameter (default 0)

std::vector<double> x(n, 0.0);

Neil Kirk
  • 20,637
  • 5
  • 51
  • 86