用fortran语言编写数值程序时,如果要计算一个大型稀疏矩阵与一个向量的乘积,可以使用下面高效的方法
1. 首先使用CSR格式大型稀疏矩阵进行存储
2. 调用mkl函数库中的mkl_dcsrsymv计算
这样做的目的不仅可以节约内存,而且计算速度也比较快示例代码如下:
program mkl_symvimplicit noneinteger, parameter        :: n = 5  !// depend on your equationinteger                   :: i, j, mm, tmp, fileid, first, numreal(kind=8)              :: matrix(n,n), x(n), y(n)real(kind=8), allocatable :: csra(:)integer, allocatable      :: ia(:), ja(:)character(len=1)          :: uplo = 'u'type                      :: nodereal(kind=8)          :: sinteger               :: k1, k2type (node), pointer  :: nextend type node type (node), pointer      :: head, tail, p, q  open ( newunit = fileid, file = 'SparseMatrix.txt' )  !// The sparse matrix data needs to be given by itselfdo i = 1, nread ( fileid,* ) matrix(i,:)end doread( fileid,* ) xclose ( fileid )!// =========================store data by CSR format=======================first = 1if ( .not.associated(p) ) thenallocate( p )q    => pnullify( p%next )q%k2 = firsttmp  = q%k2end ifnum = 0  !// calculate the number of no-zerodo i =  1, nmm = 0  !// calculate the position of no-zero in every rowdo j = i, nIf ( matrix(i,j) /= 0.0 ) thenif ( .not.associated(head) ) thenallocate( head )tail    => headnullify( tail%next )tail%s  = matrix(i,j)tail%k1 = jnum     = num + 1mm      = mm + 1elseallocate( tail%next )tail    => tail%nexttail%s  = matrix(i,j)tail%k1 = jnum     = num + 1  mm      = mm + 1  nullify( tail%next )end ifEnd ifend doif ( associated(p) ) thenallocate( q%next )q    => q%nextq%k2 = tmp + mmtmp  = q%k2nullify( q%next )end ifend doallocate( csra(num), ja(num), ia(n+1) )  !// store the no-zero element!// output a and jatail => headj = 1do if ( .not.associated(tail) ) exitcsra(j) = tail%sja(j) = tail%k1j     = j + 1tail  => tail%nextend do!// output iaq => pj = 1do if ( .not.associated(q) ) exitia(j) = q%k2j     = j + 1q     => q%nextend donullify( head, tail, p, q )write ( *,'(a)' ) '>> Original data'write ( *,'(5f7.2)' ) matrixwrite ( *,'(a)' ) '>> CSR data'write ( *,'(*(f7.2))' ) csrawrite ( *,'(a)' ) '>> X data'write ( *,'(*(f7.2))' ) xwrite ( *,'(a)' ) '>> Colnum of CSR data'write ( *,'(*(i4))' ) jawrite ( *,'(a)' ) '>> The position of CSR data'write ( *,'(*(i4))' ) iawrite ( *,'(1x,a)' ) "The result of matmul function is..."write ( *,'(*(f9.3))' ) matmul(matrix,x)call mkl_dcsrsymv( uplo, n, csra, ia, ja, x, y )print*write ( *,'(1x,a)' ) "The result of mkl_dcsrsymv is..."write ( *,'(*(f9.3))' ) yend program mkl_symv结果如下:
>> Original data1.00  -1.00   0.00  -3.00   0.00-1.00   5.00   0.00   0.00   0.000.00   0.00   4.00   6.00   4.00-3.00   0.00   6.00   7.00   0.000.00   0.00   4.00   0.00  -5.00
>> CSR data1.00  -1.00  -3.00   5.00   4.00   6.00   4.00   7.00  -5.00
>> X data-13.00   9.00  56.00  43.00 -13.00
>> Colnum of CSR data1   2   4   2   3   4   5   4   5
>> The position of CSR data1   4   5   8   9  10The result of matmul function is...-151.000   58.000  430.000  676.000  289.000The result of mkl_dcsrsymv is...-151.000   58.000  430.000  676.000  289.000
从结果可以看出,计算正确代码中用到的示例数据存储在SparseMatrix.txt中,如下所示:1.00  -1.00   0.00  -3.00   0.00-1.00   5.00   0.00   0.00   0.000.00   0.00   4.00   6.00   4.00-3.00   0.00   6.00   7.00   0.000.00   0.00   4.00   0.00  -5.00-13.00   9.00  56.00  43.00 -13.00
前五行为矩阵m,最后一行为向量v

fortran使用mkl函数库中的mkl_dcsrsymv计算矩阵与向量的乘积相关推荐

  1. fortran使用MKL函数库中的scal计算一个标量和向量的乘积

    下面的代码使用MKL函数库中的scal计算一个标量和向量的乘积 program MKL_dotcuse blas95implicit noneinteger, parameter :: n = 10r ...

  2. fortran使用MKL函数库求解普通稀疏矩阵与向量的乘积

    使用MKL函数库中的mkl_dcsrgemv可以实现普通稀疏矩阵与向量的乘积 program mainimplicit noneinteger :: n, n1, ja(9), ia(7)real*8 ...

  3. fortran使用MKL函数库计算一个复数向量的共轭与另一个复数向量的内积

    下面的代码使用MKL函数库计算了共轭向量与另一个向量的点积 program MKL_dotcuse blas95implicit noneinteger, parameter :: n = 10rea ...

  4. 转载:如何将一个新函数加到MATLAB函数库中

    如何将一个新函数加到MATLAB函数库中 nkszjx2 2017-09-29 11:25:26 13864 收藏 2 分类专栏: matlab 文章标签: matlab 库 </div> ...

  5. 利用Intel IPP函数库实现信号频谱计算

    Intel IPP(Intel Integrated Performance Primitives)函数库是一套跨平台的软件函数库,它为用户提供了一套高效.实用的函数集,可用于实现通信.图像.语音等多 ...

  6. 剑指offer刷题:javaHZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学。今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解

    题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...

  7. 剑指offer_31:HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学。今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决。但

    题目:HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量中包 ...

  8. c++调用gcd函数_c++函数库中一些实用的函数

    有一些程序,虽然写起来不难,但是可能比较麻烦或容易出错,这时就可以用c++函数库里自带的一些实用的函数. 这里只记录一些不太常见的函数. ------------------------------- ...

  9. C语言中string函数库中的一些函数的用法

    目录 1.memcpy函数 1.标准形式为 2.所对应的参数 3.该函数的返回值指向的是目标存储区 dist的指针 4.示例 2.memmoer 3.strcpy 1.函数原型 2.所对应的参数 3. ...

最新文章

  1. iOS 11开发教程(三)运行第一个iOS 11程序
  2. IntelliJ IDEA的使用操作链接
  3. c语言变长数组_2018级C语言大作业 - 祖玛
  4. jmeter ForEach控制器学习
  5. groovy怎样从sql语句中截取表名_SQl-查询篇
  6. oracle数据库11g完全卸载,oracle 11g完全卸载
  7. 路由交换笔记(27)--ACL访问控制列表之练习
  8. docker 代理_利用Docker容器实现代理转发和数据备份
  9. WAVE族函数的使用
  10. android底部显示不出来,Android studio 底部的状态栏不见了如何显示
  11. mmap java_Java文件映射[Mmap]揭秘 | 学步园
  12. 2022年最新全国各省五级行政区划代码及mysql数据库代码(省/市/区县/乡镇/村)
  13. IMX6之SPI接口驱动测试
  14. python人口普查数据数据分析_Python:第六次全国人口普查数据分析及可视化(pandas、matplotlib)...
  15. 铁路、公路施工企业劳务实名制管理系统解决方案
  16. 打印DPI如何与计算机DPI一致,像素英寸与dpi的那些事儿
  17. 塔夫茨计算机科学,塔夫斯大学计算机科学博士专业详情及要求是怎样的?
  18. 安卓手机如何把PDF文件转换为JPG图片
  19. 2款免费的安卓后台游戏
  20. 蓝桥云课linux入门4:目录结构及文件基本操作

热门文章

  1. js动态给table表格的行添加删除线
  2. Linux运维基本命令
  3. 软件工程的事实与谬误(转)
  4. android手机跑分测试,性能跑分测试与测试总结
  5. 响应式布局经典范例——巨幅背景大标题
  6. linux用户组以及权限总结
  7. Python中的函数(def)及参数传递
  8. 免费SSL证书实现https请求
  9. 【DELL】戴尔笔记本PE下没有硬盘解决方法
  10. Elasticsearch系列---聚合查询原理