本文介绍了为什么Fortran在julia基准“rand_mat_mul”中速度很慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Julia主页上的基准测试结果()显示Fortran是在rand_mat_mul基准测试中比Julia / Numpy慢了约4倍。



我不明白为什么fortran在同一个fortran库)

我也对矩阵乘法进行了fortran,julia和numpy的简单测试,得到了相似的结果:



Julia

  n = 1000; A = rand(n,n); B = rand(n,n); 
@time C = A * B;



IPython中的Numpy

 来自numpy导入* 
n = 1000; A = random.rand(n,n); B = random.rand(n,n);
%time C = dot(A,B);



Fortran

 程序测试

IMPLICIT NONE
INTEGER,PARAMETER :: N = 1000
INTEGER :: I,J
REAL * 8 :: T0,T1

REAL * 8 :: A(N,N),B(N,N),C(N,N)

CALL RANDOM_SEED()
DO I = 1,N,1
DO J = 1,N,1
CALL RANDOM_NUMBER(A(I,J))
CALL RANDOM_NUMBER(B(I,J))
END DO
END DO

call cpu_time(t0)
CALL DGEMM(N,N,N,N,N,1.D0,A,N,B,N,0.D0,C,N)
call cpu_time(t1)

write(unit = *,fmt =(a24,f10.3,a1))乘法时间:,t1-t0,s

结束课程测试




解决方案

我已将计时函数更改为system_clock(),结果证明是(我在一个程序中运行了五次)

近似于Numpy,但仍比Julia慢20%左右。


Benchmark test results on the home page of Julia (http://julialang.org/) shows that Fortran is about 4x slower than Julia/Numpy in the "rand_mat_mul" benchmark.

I can not understand that why fortran is slower while calling from the same fortran library (BLAS)??

I have also performed a simple test for matrix multiplication evolving fortran, julia and numpy and got the similar results:

Julia

n = 1000; A = rand(n,n); B = rand(n,n);
@time C = A*B;

Numpy in IPython

from numpy import *
n = 1000; A = random.rand(n,n); B = random.rand(n,n);
%time C = dot(A,B);

Fortran

PROGRAM TEST

IMPLICIT NONE
INTEGER, PARAMETER :: N = 1000
INTEGER :: I,J
REAL*8 :: T0,T1

REAL*8 :: A(N,N), B(N,N), C(N,N)

CALL RANDOM_SEED()
DO I = 1, N, 1
    DO J = 1, N, 1
        CALL RANDOM_NUMBER(A(I,J))
        CALL RANDOM_NUMBER(B(I,J))
    END DO
END DO

call cpu_time(t0)
CALL DGEMM ( "N", "N", N, N, N, 1.D0, A, N, B, N, 0.D0, C, N )
call cpu_time(t1)

write(unit=*, fmt="(a24,f10.3,a1)") "Time for Multiplication:",t1-t0,"s"

END PROGRAM TEST
解决方案

I have changed the timing function to system_clock() and result turns out to be (I run it five times in one program)

It is approximate as Numpy, but still about 20% slower than Julia.

这篇关于为什么Fortran在julia基准“rand_mat_mul”中速度很慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 02:09
查看更多