Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
68 Views

Speed of REAL*8 and COMPLEX*8 number multiplication

Hi,

I need to compare the speed of operation of REAL*8  and COMPLEX*8 number multiplication/ summation process. I used following code for that.

I presumed that real number multiplication should be at least 4 times faster than the complex number multiplication. Because mathematically we can show, to get the product of two complex numbers (e.g. product of  X= a+ib and Y=c+id  can be given as  X*Y=a*c-b*d+i(a*d+b*c) ) we need to do 4 real number multiplications.

However, when I run following code in my computer I did't see that such a difference between real and complex number multiplication process. Sometime real number multiplication time is solver than the complex number.

How that is possible to get such a results?

Is this because of that complex number multiplication process is being parallely processed?

Thanks,

Kumara

 =============code=============================

    REAL*8 :: realA(10000) ,realB(10000),realC(10000), startTime, midTime, endTime, Total_realTime, Total_complxTime
    COMPLEX*8 cmplxA(10000), cmplxB(10000), cmplxC(10000)
    integer I, K
    
    
    realA = 1.0111143434
    realB = -1.111143434

    cmplxA = (1.0111143434, 1.0111143434)
    cmplxB = (1.111143434, -1.0111143434)
 

    CALL CPU_TIME(startTime)

    DO I =1,10000000000
            DO K =1, 10000
                realC(K) = realA(K)*realB(K)+realA(K)*realB(K)
            ENDDO
    ENDDO 

    CALL CPU_TIME(midTime)

    DO I =1,10000000000
            DO K =1, 10000
                cmplxC(K) = cmplxA(K)*cmplxB(K)+cmplxA(K)*cmplxB(K)
            ENDDO
    ENDDO 

    CALL CPU_TIME(endTime)
    

    Total_realTime= midTime - startTime
    Total_complxTime = endTime- midTime

    WRITE(*,*) 'REAL NUMBER OPERATION TIME', realTime
    WRITE(*,*) 'COMPLEX NUMBER OPERATION TIME',complxTime

0 Kudos
2 Replies
Highlighted
Employee
68 Views

This is because you are doing double precision real multiplication but single precision complex multiplication.

I think the misunderstanding is in COMPLEX*8  -  this allocates 8 bytes to the complex number, so it consists of two 4-byte reals, i.e., single precision.

If you would use COMPLEX(8) instead, the complex data type consists of two 8-byte reals, so 16 bytes in all.  (Reals don't have this problem, REAL*8 is the same as REAL(8) ).  If you run with COMPLEX(8), you should see that complex multiplications run several times slower than real ones, since you are doing 4 real multiplications, an addition and a subtraction. (And possibly a shuffle, if part of a vectorized loop).

0 Kudos
Highlighted
Beginner
68 Views

It make sense, thank you very much

0 Kudos