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
  • 23,572
  • 15
  • 99
  • 156
Eissa N.
  • 1,695
  • 11
  • 18

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,423
  • 14
  • 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
  • 21,327
  • 9
  • 53
  • 91