Can I make my code faster with parallelism, or just plain better coding?

I think you misread @aaowens’s code, this A[i] += abc means “copy abc to location i of vector A”. This works because A is mutable (even though its elements are not). Thus A[i][1] += B[i][1] would not work because A[i][1] is a field of a SVector and thus cannot be updated.

To fill an SVector, see Constructing SVector with a loop - #7 by tkf. But for your example just do SVector(-fdx, -fdy, f*dz).

2 Likes