helloword3.c 显示每个进程执行在哪个机器节点上


  1. #include<stdio.h>        
  2. #include"mpi.h"  
  3.   
  4. int main(int argc, char *argv[]){    
  5.         int totalTaskNum, rankID;  
  6.           
  7.         int rt = MPI_Init(&argc, &argv);  
  8.         if(rt != MPI_SUCCESS){    
  9.                 printf("Error starting MPI.\n");  
  10.                 MPI_Abort(MPI_COMM_WORLD, rt);  
  11.         }  
  12.   
  13.         MPI_Comm_size(MPI_COMM_WORLD, &totalTaskNum);       
  14.         MPI_Comm_rank(MPI_COMM_WORLD, &rankID);    
  15.   
  16.         char processorName[MPI_MAX_PROCESSOR_NAME];  //  
  17.         int  resultLength;                           //  
  18.         MPI_Get_processor_name(processorName,&resultLength);//  
  19.   
  20.         printf("Hellow, world! %dth of totalTaskNum = %d on %s\n", rankID, totalTaskNum, processorName);//add "on %s", processName    
  21.         MPI_Finalize();       
  22.   
  23.         return 0;       

2. 编译执行

[plain]  view plain copy
  1. [amao@amao991 mpi-study]$ mpicc -o helloworld3 helloworld3.c  
  2. [amao@amao991 mpi-study]$ mpiexec -n 10 ./helloworld3  
  3. Hellow, world! 0th of totalTaskNum = 10 on amao991  
  4. Hellow, world! 1th of totalTaskNum = 10 on amao991  
  5. Hellow, world! 2th of totalTaskNum = 10 on amao991  
  6. Hellow, world! 6th of totalTaskNum = 10 on amao991  
  7. Hellow, world! 9th of totalTaskNum = 10 on amao991  
  8. Hellow, world! 3th of totalTaskNum = 10 on amao991  
  9. Hellow, world! 7th of totalTaskNum = 10 on amao991  
  10. Hellow, world! 8th of totalTaskNum = 10 on amao991  
  11. Hellow, world! 4th of totalTaskNum = 10 on amao992  
  12. Hellow, world! 5th of totalTaskNum = 10 on amao992  

3. 总结

    (1)amao991上分配4个(process 0~3),然后amao992分配两个(process 4-5),然后amao991再分配4个(process 6-9)

    (2)函数  MPI_Get_processor_name(processorName,&resultLength);

        详细解释见: 连接1     连接2
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值