Prog2: hellowrold2.c 由进程0打印执行时间和命令行参数
2011-12-21 11:30
309 查看
1. 源码
2. 编译执行
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)源码
(2)编译执行
#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 ./helloworld2 Hellow, world! 0th of totalTaskNum = 10 elapsedTime = 0.000029, precision = 0.000001 Hellow, world! 1th of totalTaskNum = 10 Hellow, world! 2th of totalTaskNum = 10 Hellow, world! 3th of totalTaskNum = 10 Hellow, world! 6th of totalTaskNum = 10 Hellow, world! 4th of totalTaskNum = 10 Hellow, world! 7th of totalTaskNum = 10 Hellow, world! 8th of totalTaskNum = 10 Hellow, world! 9th of totalTaskNum = 10 Hellow, 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 xian Hellow, world! 0th of totalTaskNum = 10 argc = 4 0th of arguments is: ./helloworld2 1th of arguments is: beijing 2th of arguments is: shanghai 3th of arguments is: xian elapsedTime = 0.000041, precision = 0.000001 Hellow, world! 1th of totalTaskNum = 10 Hellow, world! 6th of totalTaskNum = 10 Hellow, world! 7th of totalTaskNum = 10 Hellow, world! 8th of totalTaskNum = 10 Hellow, world! 9th of totalTaskNum = 10 Hellow, world! 2th of totalTaskNum = 10 Hellow, world! 3th of totalTaskNum = 10 Hellow, world! 4th of totalTaskNum = 10 Hellow, world! 5th of totalTaskNum = 10
相关文章推荐
- 创建进程并在某段时间后执行方法
- Linux获取进程执行时间
- 两个线程A和B,任务都是打印当前时间,要求编码实现:线程A和B同时启动后,以先A后B的方式任务交叉执行10次。
- linux获取进程执行时间方法示例
- [Linux小技巧]如何查询进程执行时间
- MyBatis插件及示例----打印每条SQL语句及其执行时间
- MyBatis插件及示例----打印每条SQL语句及其执行时间
- Sprint AOP 打印方法执行时间。
- linux 打印相关 应用的进程,根据筛选条件 获取进程id 执行jstack 指令
- Android小技巧——利用TimingLogger打印程序的执行时间
- oracle 中--怎么查看当前表空间在作什么操作?--查锁,死锁,当前执行时间长的Sql语句,没提交的事务,对象为哪些进程所用
- 时间以及执行所有命令行参数
- c#关闭系统进程以及如何调用cmd并执行命令开发者在线 Builder.com.cn 更新时间:2008-08-05作者:乔毅 来源:IT168
- linux获取进程执行时间方法
- [Linux进程]统计进程的执行时间
- DebugLog 打印方法执行时间
- log4j2打印Mybatis执行的SQL语句及SQL语句的执行时间
- spring aop实现打印方法执行时间
- fork()子进程与父进程执行打印多少个-号问题
- mybatis插件-打印 SQL 及其执行时间