0

I have converted this python eimsum expression

psi_p = np.einsum('ij...,j...->i...', exp_p, psi_p)

to c++ like this:

 int io=0;
`for (i=0; i < 4; i++){             
    ikauxop=i*nd;
    for (j=0; j < 4; j++){    
        jkpsi=nd*j;     
        for (k=0; k < m_N; k++){                            
            m_auxop[ikauxop+k] +=  m_opK [io++] * m_wf[jkpsi + k];      
        }
    }               
}

But in phyton is 2 times faster than in c++.

m_auxop and m_wf are 2d array flatten in 1D, and m_opK is a 3d array flatten in 1D, so I wonder who can I speed this in c++? `

The array types are std::complex, and I tried with flatten or not arrays and I get the same time

Luis ALberto
  • 103
  • 3
  • 2
    Simple numpy einsum computations may be able to take advantage of blas libraries, which is what happens in this case. Are you compiling your C++ code with the correct flags to enable autovectorization? – Niteya Shah Dec 05 '22 at 02:51
  • Something related: [Why is matrix multiplication faster with numpy than with ctypes in Python?](https://stackoverflow.com/questions/10442365/why-is-matrix-multiplication-faster-with-numpy-than-with-ctypes-in-python) and [Why is my Python NumPy code faster than C++?](https://stackoverflow.com/questions/41365723/why-is-my-python-numpy-code-faster-than-c) – Ranoiaetep Dec 05 '22 at 04:39
  • Don't know about that flags, the IDE I used is MFC VC++6 in XP32, but I have CodeBlocks and QT on Lubuntu 18. Anyw3ay thanks I'll take a look at those links, – Luis ALberto Dec 05 '22 at 18:03

0 Answers0