With that said my question is whether the time access to vector elements by means of [] will increase with the size of a vector? |
The elements are consecutive and the complexity O(1).
Any given element n is exactly
n * sizeof(value_type)
bytes from the start.
The
sizeof(value_type)
is a compile-time constant.
A
p + n * s
is one multiply and one addition, no matter what values the p, n and s have. A 3D version of it has more operations, but is still O(1).
However, there are
hardware-dependent factors at the background. The RAM within CPU are fast, but small. You probably cannot fit entire vector into CPU. The CPU loads a block of bytes from slow main memory into CPU's fast memory. The block is more than one value.
If the next instructions need values from the same block, those are already loaded --
cached.
If the next values are elsewhere, a different block has to be retrieved into the cache -- a cache miss.
A sub-block of 3D matrix is probably not continuous. (That can be good or bad, depending on data access pattern.)
It can be beneficial to rearrange data in some ways, but CPU types are different; there is no one data layout strategy that would be optimal everywhere.
1. Are you sure that there are no other algorithmic complexity? Can you profile the job to show that vector operations are the primary problem?
2. Is it possible to run that simulation in parallel? Threaded? MPI? GPGPU? They do have their downsides, but are very effective in some problems.