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

mpi (message passing model)in c printf error

我是 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();
}    

您缺少 MPI_Get_processor_name 函数中的参数

用这一行替换你的函数调用并初始化长度 var (int)

 int name_len; //12 characters
 MPI_Get_processor_name(processor_name, &name_len);