The most efficient way to initialize a large doubling block in C

What is the easiest / most efficient way to initialize these doubling blocks, preferably at compile time:

#define N 1000
double mul1[N][N] __attribute__ ((aligned (64)));
double mul2[N][N] __attribute__ ((aligned (64)));

They are used for test data for " const" only.

+3
source share
4 answers

There is a GCC function (not standard C!) Called Assigned Initializers

For a 1D array, this will be simple:

double array[N] = {[0 ... (N-1)] = MY_DOUBLE_VALUE};

For 2D, a little harder:

double array[N][N] = { [0 ... (N-1)] = {[0 ... (N-1)] = MY_DOUBLE_VALUE}};
+4
source

The initialization of a static array (which I accept is what you want) is ALWAYS performed at compile time, so you initialize them just like any other array.

+3

, , make.

- , Boost.Preprocessor. BOOST_PP_WHILE BOOST_PP_ARRAY_PUSH_FRONT.

, :)

+1

. ?

- . ?

int i, j;
for (i = 0; i < N; ++i) {
  for (j = 0; j < N; ++j) {
    mul1[i][j] = INITIAL_VALUE_1;
    mul2[i][j] = INITIAL_VALUE_2;
  }
}

, ? , ?

+1

Source: https://habr.com/ru/post/1726787/


All Articles