1. 根据Prog1改写
(1)amao991上分配4个(process 0~3),然后amao992分配两个(process 4-5),然后amao991再分配4个(process 6-9)
(2)函数 MPI_Get_processor_name(processorName,&resultLength);
详细解释见: 连接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); } MPI_Comm_size(MPI_COMM_WORLD, &totalTaskNum); MPI_Comm_rank(MPI_COMM_WORLD, &rankID); char processorName[MPI_MAX_PROCESSOR_NAME]; // int resultLength; // MPI_Get_processor_name(processorName,&resultLength);// printf("Hellow, world! %dth of totalTaskNum = %d on %s\n", rankID, totalTaskNum, processorName);//add "on %s", processName MPI_Finalize(); return 0; }
2. 编译执行
3. 总结[amao@amao991 mpi-study]$ mpicc -o helloworld3 helloworld3.c [amao@amao991 mpi-study]$ mpiexec -n 10 ./helloworld3 Hellow, world! 0th of totalTaskNum = 10 on amao991 Hellow, world! 1th of totalTaskNum = 10 on amao991 Hellow, world! 2th of totalTaskNum = 10 on amao991 Hellow, world! 6th of totalTaskNum = 10 on amao991 Hellow, world! 9th of totalTaskNum = 10 on amao991 Hellow, world! 3th of totalTaskNum = 10 on amao991 Hellow, world! 7th of totalTaskNum = 10 on amao991 Hellow, world! 8th of totalTaskNum = 10 on amao991 Hellow, world! 4th of totalTaskNum = 10 on amao992 Hellow, world! 5th of totalTaskNum = 10 on amao992
(1)amao991上分配4个(process 0~3),然后amao992分配两个(process 4-5),然后amao991再分配4个(process 6-9)
(2)函数 MPI_Get_processor_name(processorName,&resultLength);
详细解释见: 连接1 连接2