Answer the question
In order to leave comments, you need to log in
What is the best way to allocate an array of complex numbers in RAM in terms of performance?
In two arrays: double re[N]; doubleim[N]; or in one double c[2*N], where the real and imaginary parts alternate?
Is there any difference in terms of performance? Maybe in the second case, the processor cache works better, because. Are the real and imaginary parts of a number used at the same time?
It is more convenient for me in two arrays.
PS I know about structures and readability.
Also, I remember that some popular math libraries keep the real and imaginary parts separate. For example, UMFPACK supports both options. Logic also tells me that it is better to use one array, but I'm not sure, I would like some confirmation, test results ...
Answer the question
In order to leave comments, you need to log in
If you want to be cache friendly, then you need data access locality.
Therefore, it is better to alternate real and imaginary parts in one array. Or, even better, create a structure with two fields and store an array of them. Here in memory, the arrangement of data will be the same, but the code will be readable and logical.
It is more convenient to use an array of structures:
struct complex_t {
float re, im;
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question