<small id='rv9bL'></small><noframes id='rv9bL'>

  1. <tfoot id='rv9bL'></tfoot>
    <i id='rv9bL'><tr id='rv9bL'><dt id='rv9bL'><q id='rv9bL'><span id='rv9bL'><b id='rv9bL'><form id='rv9bL'><ins id='rv9bL'></ins><ul id='rv9bL'></ul><sub id='rv9bL'></sub></form><legend id='rv9bL'></legend><bdo id='rv9bL'><pre id='rv9bL'><center id='rv9bL'></center></pre></bdo></b><th id='rv9bL'></th></span></q></dt></tr></i><div id='rv9bL'><tfoot id='rv9bL'></tfoot><dl id='rv9bL'><fieldset id='rv9bL'></fieldset></dl></div>

  2. <legend id='rv9bL'><style id='rv9bL'><dir id='rv9bL'><q id='rv9bL'></q></dir></style></legend>

      <bdo id='rv9bL'></bdo><ul id='rv9bL'></ul>

    1. 为什么 Fortran 在 julia 基准测试“rand_mat_mul"中很慢?

      Why Fortran is slow in the julia benchmark quot;rand_mat_mulquot;?(为什么 Fortran 在 julia 基准测试“rand_mat_mul中很慢?)
      <legend id='KxuTs'><style id='KxuTs'><dir id='KxuTs'><q id='KxuTs'></q></dir></style></legend>

          <bdo id='KxuTs'></bdo><ul id='KxuTs'></ul>
          <tfoot id='KxuTs'></tfoot>

              <small id='KxuTs'></small><noframes id='KxuTs'>

                  <tbody id='KxuTs'></tbody>
              • <i id='KxuTs'><tr id='KxuTs'><dt id='KxuTs'><q id='KxuTs'><span id='KxuTs'><b id='KxuTs'><form id='KxuTs'><ins id='KxuTs'></ins><ul id='KxuTs'></ul><sub id='KxuTs'></sub></form><legend id='KxuTs'></legend><bdo id='KxuTs'><pre id='KxuTs'><center id='KxuTs'></center></pre></bdo></b><th id='KxuTs'></th></span></q></dt></tr></i><div id='KxuTs'><tfoot id='KxuTs'></tfoot><dl id='KxuTs'><fieldset id='KxuTs'></fieldset></dl></div>

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

                问题描述

                Julia 主页 (http://julialang.org/) 上的基准测试结果表明,Fortran 是在rand_mat_mul"基准测试中比 Julia/Numpy 慢约 4 倍.

                我不明白为什么从同一个 fortran 库 (BLAS) 调用时 fortran 速度较慢??

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

                朱莉娅

                n = 1000;A = 兰德(n,n);B = 兰德(n,n);@时间 C = A*B;

                <块引用>

                >> 经过时间:0.069577896 秒(已分配 7 MB)

                IPython 中的 Numpy

                从 numpy 导入 *n = 1000;A = 随机数.rand(n,n);B = 随机数.rand(n,n);%时间 C = 点(A,B);

                <块引用>

                >> 挂墙时间:98 毫秒

                Fortran

                程序测试隐式无整数,参数 :: N = 1000整数 :: I,J真实*8 :: T0,T1实数*8 :: A(N,N), B(N,N), C(N,N)调用随机种子()DO I = 1, N, 1DO J = 1, N, 1CALL RANDOM_NUMBER(A(I,J))CALL RANDOM_NUMBER(B(I,J))结束做结束做调用 cpu_time(t0)调用 DGEMM(N"、N"、N、N、N、1.D0、A、N、B、N、0.D0、C、N)调用 cpu_time(t1)write(unit=*, fmt="(a24,f10.3,a1)") "乘法时间:",t1-t0,"s"结束程序测试

                <块引用>

                gfortran test_blas.f90 libopenblas.dll -O3 &一个.exe

                >> 乘法时间:0.296s

                解决方案

                我把计时函数改成 system_clock() 结果是(我在一个程序中运行了五次)

                <块引用>

                乘法时间:92ms

                乘法时间:92ms

                乘法时间:89ms

                乘法时间:85ms

                乘法时间:94ms

                它近似于 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;
                

                >> elapsed time: 0.069577896 seconds (7 MB allocated)

                Numpy in IPython

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

                >> Wall time: 98 ms

                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
                

                gfortran test_blas.f90 libopenblas.dll -O3 & a.exe

                >> Time for Multiplication: 0.296s

                解决方案

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

                Time for Multiplication: 92ms

                Time for Multiplication: 92ms

                Time for Multiplication: 89ms

                Time for Multiplication: 85ms

                Time for Multiplication: 94ms

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

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                Pandas - group by column and transform the data to numpy array(Pandas - 按列分组并将数据转换为 numpy 数组)
                Iterate over 36 million items in a list of tuples in python efficiently and faster(在 python 的元组列表中有效且更快地迭代超过 3600 万个项目)
                shallow iteration with nditer(使用 nditer 进行浅迭代)
                Assigning a variable NaN in python without numpy(在没有numpy的python中分配一个变量NaN)
                <i id='NFubG'><tr id='NFubG'><dt id='NFubG'><q id='NFubG'><span id='NFubG'><b id='NFubG'><form id='NFubG'><ins id='NFubG'></ins><ul id='NFubG'></ul><sub id='NFubG'></sub></form><legend id='NFubG'></legend><bdo id='NFubG'><pre id='NFubG'><center id='NFubG'></center></pre></bdo></b><th id='NFubG'></th></span></q></dt></tr></i><div id='NFubG'><tfoot id='NFubG'></tfoot><dl id='NFubG'><fieldset id='NFubG'></fieldset></dl></div>
                    <tbody id='NFubG'></tbody>

                      1. <small id='NFubG'></small><noframes id='NFubG'>

                      2. <tfoot id='NFubG'></tfoot>
                        <legend id='NFubG'><style id='NFubG'><dir id='NFubG'><q id='NFubG'></q></dir></style></legend>
                          <bdo id='NFubG'></bdo><ul id='NFubG'></ul>