optimization - Optimization of conditional Fortran loop
问题描述
I would like to optimize for speed the following block of code:
DO i=1, dim1
DO j=1, dim2
DO k=1, dim3
IF (A(k,j,i)>0) &
B(k,j,i) = exp(C(k))/A(k,j,i)
ENDDO
ENDDO
ENDDO
Very importantly, A
is an INTEGER
and B
and C
are COMPLEX
!
There are two issues: 1) How to replace this by a BLAS/LAPACK call? The issue is the condition. 2) Calculation of the exp is slow. How to speed that up?
解决方案
idim[1-3]
我用各种排列进行了几次测试,[40,40,1000]
发现使用临时数组作为指数并保持原始循环排序比提供的其他答案快 2 倍或更多。您的里程可能因编译器等而异。
d=exp(c)
DO i=1, dim1
DO j=1, dim2
DO k=1, dim3
IF (A(k,j,i)>0) &
B(k,j,i) = d(k)/A(k,j,i)
ENDDO
ENDDO
ENDDO
推荐阅读
- python - 组合不同的对象包含图表和数据框(表格)和段落(降价)到单个 html 报告中
- python - 在 keras >2.0 中使用什么来代替 mode='mul' 的合并?
- material-ui - 带有微调器的 MaterialUI CardMedia 图像
- c# - asp.net 级联下拉列表
- c#-4.0 - 使用文件类写入文件
- sql-server - 获取不同的employee_id时子查询返回超过1个值
- java - 没有颜色对话框按钮的 JavaFX 调色板
- vue.js - Vue/Nuxt:如何定义一个所有组件都可以访问的全局方法?
- cytoscape.js - 以一个节点为中心的布局
- javascript - 无法通过本机 NodeJS UDP API 发送 UDP 数据包