Prog2: hellowrold2.c 由进程0打印执行时间和命令行参数
来源:互联网 发布:水利水电设计院知乎 编辑:程序博客网 时间:2024/06/05 06:51
1. 源码
#include<stdio.h>#include"mpi.h"int main(int argc, char *argv[]){ int totalTaskNum, rankID; int rt = MPI_Init(&argc, &argv); if(rt != MPI_SUCCESS){ printf("Error starting MPI.\n"); MPI_Abort(MPI_COMM_WORLD, rt); } double wallTime1 = MPI_Wtime(); //starting time double precision = MPI_Wtick(); //WallTime's precision MPI_Comm_size(MPI_COMM_WORLD, &totalTaskNum); MPI_Comm_rank(MPI_COMM_WORLD, &rankID); printf("Hellow, world! %dth of totalTaskNum = %d\n", rankID, totalTaskNum); double wallTime2 = MPI_Wtime(); if(rankID == 0){ //if(!rankID) printf("elapsedTime = %f, precision = %f\n", wallTime2 - wallTime1, precision); } MPI_Finalize(); return 0;}
2. 编译执行
[amao@amao991 mpi-study]$ mpicc -o helloworld2 helloworld2.c[amao@amao991 mpi-study]$ mpiexec -n 10 ./helloworld2Hellow, world! 0th of totalTaskNum = 10elapsedTime = 0.000029, precision = 0.000001Hellow, world! 1th of totalTaskNum = 10Hellow, world! 2th of totalTaskNum = 10Hellow, world! 3th of totalTaskNum = 10Hellow, world! 6th of totalTaskNum = 10Hellow, world! 4th of totalTaskNum = 10Hellow, world! 7th of totalTaskNum = 10Hellow, world! 8th of totalTaskNum = 10Hellow, world! 9th of totalTaskNum = 10Hellow, world! 5th of totalTaskNum = 10
3. 总结
(1)学习了两个函数
double wallTime1 = MPI_Wtime(); //进程组的墙上时间, 在并行执行开头/结尾分别获取墙上时间,以second为单位
double precision = MPI_Wtick(); //WallTime's precision,double双精度,以second为单位(2) 由0号进程来打印结果
if(rankID == 0){ //if(!rankID)
4. 补充: 修改一下,由0号进程获取命令行参数并打印出来
(1)源码
#include<stdio.h>#include"mpi.h"int main(int argc, char *argv[]){ int totalTaskNum, rankID; int rt = MPI_Init(&argc, &argv); if(rt != MPI_SUCCESS){ printf("Error starting MPI.\n"); MPI_Abort(MPI_COMM_WORLD, rt); } double wallTime1 = MPI_Wtime(); //starting time double precision = MPI_Wtick(); //WallTime's precision MPI_Comm_size(MPI_COMM_WORLD, &totalTaskNum); MPI_Comm_rank(MPI_COMM_WORLD, &rankID); printf("Hellow, world! %dth of totalTaskNum = %d\n", rankID, totalTaskNum); double wallTime2 = MPI_Wtime(); if(rankID == 0){ //if(!rankID) printf("argc = %d\n", argc); int i; for(i = 0; i < argc; i++){ printf("%dth of arguments is: %s\n", i, argv[i]); } printf("elapsedTime = %f, precision = %f\n", wallTime2 - wallTime1, precision); } MPI_Finalize(); return 0;}
(2)编译执行[amao@amao991 mpi-study]$ mpicc -o helloworld2 helloworld2.c [amao@amao991 mpi-study]$ mpiexec -n 10 ./helloworld2 beijing shanghai xianHellow, world! 0th of totalTaskNum = 10argc = 40th of arguments is: ./helloworld21th of arguments is: beijing2th of arguments is: shanghai3th of arguments is: xianelapsedTime = 0.000041, precision = 0.000001Hellow, world! 1th of totalTaskNum = 10Hellow, world! 6th of totalTaskNum = 10Hellow, world! 7th of totalTaskNum = 10Hellow, world! 8th of totalTaskNum = 10Hellow, world! 9th of totalTaskNum = 10Hellow, world! 2th of totalTaskNum = 10Hellow, world! 3th of totalTaskNum = 10Hellow, world! 4th of totalTaskNum = 10Hellow, world! 5th of totalTaskNum = 10
- Prog2: hellowrold2.c 由进程0打印执行时间和命令行参数
- Linux进程-命令行参数和环境列表
- Linux进程-命令行参数和环境列表
- Linux进程-命令行参数和环境列表
- 获取进程命令行参数
- 查看进程命令行参数
- 【C/C++】命令行参数
- linux下如何获取进程的id和命令行参数
- Erlang 测量进程执行时间和reduction
- 获取进程的命令行参数
- xp 查看进程命令行参数
- windows 命令行获取进程参数
- C C++ 命令行参数
- C/C++命令行参数
- C命令行参数
- c命令行参数
- C语言命令行参数
- c 语言 命令行参数
- Linux驱动 probe函数调用
- JQuery中$(function() {...}
- 网站对历史发布信息进行备份和查阅的相关管理制度及执行情况说明
- Checkbox
- 从HelloWorld看iphone程序的生命周期
- Prog2: hellowrold2.c 由进程0打印执行时间和命令行参数
- Spring依赖的Jar包简介
- 职场礼仪
- “复制”,“粘贴”
- SQL Azure Federation Exercise
- php header头部发送总结
- dbtype,sqldbtype两者对应关系
- 获取工程路径
- 移动视频监控