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

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? Commented Dec 5, 2022 at 2:51
  • Something related: Why is matrix multiplication faster with numpy than with ctypes in Python? and Why is my Python NumPy code faster than C++? Commented Dec 5, 2022 at 4: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, Commented Dec 5, 2022 at 18:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.