当前位置: 首页 > news >正文

Fortran: select type

Fortran: select type

实现类似C++的template函数功能

module M_reduceuse mpi_f08interface reducemodule procedure reduce_scalar,reduce_arrayend interface reducecontains!!https://docs.open-mpi.org/en/v5.0.x/man-openmpi/man3/MPI_Reduce.3.htmlsubroutine reduce_array(n,x,op,root,comm)implicit noneinteger::nclass(*)::x(n)type(MPI_Op)::op!optional integer,optional::roottype(MPI_Comm),optional::comm!localinteger::my_root,my_ranktype(MPI_Comm)::my_commtype(MPI_Datatype)::dtypeinteger::ierr my_root=0if(present(root)) thenmy_root=rootend ifmy_comm=MPI_COMM_WORLDif(present(comm)) thenmy_comm=commend ifselect type(x)type is (integer)dtype=MPI_INTEGERtype is(logical)dtype=MPI_LOGICALtype is(real(4))dtype=MPI_REAL4type is(real(8))dtype=MPI_REAL8class defaulterror stop 'unsupported type'end selectcall MPI_Comm_rank(my_comm,my_rank,ierr)if(my_rank==my_root) thencall MPI_Reduce(MPI_IN_PLACE,x,n,dtype,op,my_root,my_comm,ierr)elsecall MPI_Reduce(x,MPI_IN_PLACE,n,dtype,op,my_root,my_comm,ierr)endif!!call CHECKMPI(ierr)end subroutine reduce_arraysubroutine reduce_scalar(x,op,root,comm)implicit noneclass(*)::xtype(MPI_Op)::op!optional integer,optional::roottype(MPI_Comm),optional::comm!localinteger::my_root,my_ranktype(MPI_Comm)::my_commtype(MPI_Datatype)::dtypeinteger::ierr my_root=0if(present(root)) thenmy_root=rootend ifmy_comm=MPI_COMM_WORLDif(present(comm)) thenmy_comm=commend ifselect type(x)type is (integer)dtype=MPI_INTEGERtype is(logical)dtype=MPI_LOGICALtype is(real(4))dtype=MPI_REAL4type is(real(8))dtype=MPI_REAL8class defaulterror stop 'unsupported type'end selectcall MPI_Comm_rank(my_comm,my_rank,ierr)if(my_rank==my_root) thencall MPI_Reduce(MPI_IN_PLACE,x,1,dtype,op,my_root,my_comm,ierr)elsecall MPI_Reduce(x,MPI_IN_PLACE,1,dtype,op,my_root,my_comm,ierr)endif!!call CHECKMPI(ierr)end subroutine reduce_scalarend module M_reduce

参考

Fortran OOP-03:继承和多态

http://www.lryc.cn/news/352194.html

相关文章:

  • QEMU启动Linux内核
  • Golang | Leetcode Golang题解之第109题有序链表转换二叉搜索树
  • Qt快速入门到熟练(电子相册项目(一))
  • 机械臂与Realsense D435 相机的手眼标定ROS包
  • ubuntu使用记录——如何使用wireshark网络抓包工具进行检测速腾激光雷达的ip和端口号
  • C#学习指南:重要内容与实用技巧
  • display(a,b)什么意思
  • SpringBoot3整合阿里云短信服务-1(配置阿里云短信服务)
  • 基于HAL库控制LED流水灯
  • 利用kubeadm安装k8s集群 以及跟harbor私有仓库下载镜像
  • 明天(周六)下午!武汉Linux爱好者线下沙龙,我们在华中科技大学等你!
  • MySQL主从复制(五):读写分离
  • 阿里巴巴 EasyExcel 真正的高效与通用导入(亿级数据秒级导入)
  • 32.5k star!!替换 postman?【送源码】
  • 课时135:awk实践_逻辑控制_综合实践
  • c++ 读取MNIST数据集实现softmax回归
  • JS-04何为继承以及实现方式
  • 6款网站登录页(附带源码)
  • spring boot打的包直接运行
  • 移除元素-力扣
  • 代码随想录算法训练营第三天| 203.移除链表元素、 707.设计链表、 206.反转链表
  • 【题解】AB33 相差不超过k的最多数(排序 + 滑动窗口)
  • LSPatch免root手机模块应用
  • 深入解析kube-scheduler的算法自定义插件
  • java原型模式 (Prototype Pattern) 介绍
  • LLama3 | 一. 本地 Web Demo 部署
  • MariaDB 给指定列值自动加密(持久数据加触发器)
  • 深入理解Linux系统管理与网络配置高级指南
  • 朴素贝叶斯+SMSSpamCollections
  • 【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手