Author: tlinnet Date: Sun Jun 15 15:57:33 2014 New Revision: 23964 URL: http://svn.gna.org/viewcvs/relax?rev=23964&view=rev Log: Implemented the BLAS method of dot product, which should be faster. I cannot get the "out" argument to work. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py Modified: branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py?rev=23964&r1=23963&r2=23964&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py Sun Jun 15 15:57:33 2014 @@ -56,6 +56,7 @@ # Python module imports. from numpy import asarray, dot, fabs, isfinite, log, min, sum from numpy.ma import fix_invalid, masked_where +from scipy.linalg.blas import dgemm as blas_dot # relax module imports. @@ -158,14 +159,31 @@ # This matrix is a propagator that will evolve the magnetization with the matrix R for a delay tcp. Rexpo = matrix_exponential(R*tcp_si_mi_di) + # The numpy way. Give dot two matrices that are both C_CONTIGUOUS, then the performance is better: # The essential evolution matrix. # This is the first round. - dot(Rexpo, r180x, evolution_matrix) - evolution_matrix = dot(evolution_matrix, Rexpo) + #dot(Rexpo.T, r180x.T, evolution_matrix) + #evolution_matrix = dot(evolution_matrix, Rexpo) # The second round. - evolution_matrix = dot(evolution_matrix, evolution_matrix) + #evolution_matrix = dot(evolution_matrix, evolution_matrix) # The third and fourth round, - evolution_matrix = dot(evolution_matrix, evolution_matrix) + #evolution_matrix = dot(evolution_matrix, evolution_matrix) + + # Give dot two matrices that are both F_CONTIGUOUS, we can use BLAS through the method: + # The become F_CONTIGUOUS by transposing them. + # See by: print Rexpo.flags.c_contiguous, Rexpo.T.flags.c_contiguous + # http://wiki.scipy.org/PerformanceTips + # The FORTRAN code. + # tchar=s,d,c,z>gemm(m,n,k,alpha,a,b,beta,c,trans_a,trans_b,lda,ka,ldb,kb) + # ! c = gemm(alpha,a,b,beta=0,c=0,trans_a=0,trans_b=0,overwrite_c=0) + # ! Calculate C <- alpha * op(A) * op(B) + beta * C + # This is the first round. + evolution_matrix[:] = blas_dot(alpha=1.0, a=Rexpo.T, b=r180x.T, trans_a=True, trans_b=True) + evolution_matrix[:] = blas_dot(alpha=1.0, a=evolution_matrix.T, b=Rexpo.T, trans_a=True, trans_b=True) + # The second round. + evolution_matrix[:] = blas_dot(alpha=1.0, a=evolution_matrix.T, b=evolution_matrix.T, trans_a=True, trans_b=True) + # The third and fourth round. + evolution_matrix[:] = blas_dot(alpha=1.0, a=evolution_matrix.T, b=evolution_matrix.T, trans_a=True, trans_b=True) # Loop over the CPMG elements, propagating the magnetisation. for j in range(power_si_mi_di/2):