= Source code = {{{ /* Program: * 每個 node 將自己的 id 印出,並且將所有的參與運動的 node 總數也印出 * ,顯示出自己的主機名稱。 * History: * 2008-04-09 BETA * 2008-06-25 增加顯示主機名稱功能 */ #include #include main (int argc, char **argv) { int rank, size, len; char name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); int myid, numprocs; /* 取得 node 總數 */ MPI_Comm_size(MPI_COMM_WORLD,&numprocs); /* 取得本身 node id / rank */ MPI_Comm_rank(MPI_COMM_WORLD,&myid); /* 取得本身 host name */ MPI_Get_processor_name(name, &len); printf("This is machine %d of %d name = %s\n", myid, numprocs, name); MPI_Finalize(); } }}} = Result = [[Image(demo1-01.png)]] = Related functions = [wiki:mpich/MPI_Comm_size]、[wiki:mpich/MPI_Comm_rank]。