c printf中的mpi(消息传递模型)错误

c printf中的mpi(消息传递模型)错误,c,mpi,C,Mpi,我是MPI新手。我不知道如何去爱它。在c中,printf显示输出,但在mpi中,printf函数显示错误 代码: #include <mpi.h> #include <stdio.h> #include<stdlib.h> #include<time.h> int main(int argc, char* argv[]) { // Initialize the MPI environment MPI_Init(&

我是MPI新手。我不知道如何去爱它。在c中,printf显示输出,但在mpi中,printf函数显示错误

代码:

#include <mpi.h>
#include <stdio.h>
#include<stdlib.h>
#include<time.h>

int main(int argc, char* argv[]) {
    
    // Initialize the MPI environment
    MPI_Init(&argc, &argv);
    
    // Get the number of processes
    int P;  //total number of processes 
    MPI_Comm_size(MPI_COMM_WORLD, &P);
    
    // Get the rank of the process
    int my_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    // Get the name of the processor
    char processor_name[MPI_MAX_PROCESSOR_NAME]; //256
 
    MPI_Get_processor_name(processor_name);

    
    printf("\nHello world from process:%d out of %d, mapped on processor:%s\n");
    MPI_Finalize();
}    

#包括
#包括
#包括
#包括
int main(int argc,char*argv[]){
//初始化MPI环境
MPI_Init(&argc,&argv);
//获取进程数
int P;//进程总数
MPI通信大小(MPI通信世界和P);
//获取进程的等级
int我的_等级;
MPI通信等级(MPI通信世界和我的通信等级);
//获取处理器的名称
字符处理器名称[MPI_MAX_处理器名称];//256
MPI\u获取\u处理器\u名称(处理器\u名称);
printf(“\n来自进程%d(共%d个),映射到处理器%s\n”);
MPI_Finalize();
}    

您缺少MPI\u Get\u processor\u name函数中的参数

用此行替换函数调用,并初始化长度变量(int)


使用
-Wall
编译,并修复与
printf
相关的警告。
 int name_len; //12 characters
 MPI_Get_processor_name(processor_name, &name_len);