gpt4 book ai didi

c - 如何在 mpi : cannot connect to local mpd (/tmp/mpd2. console_karim 中运行 C 代码);可能的原因?

转载 作者:太空宇宙 更新时间:2023-11-04 04:12:24 25 4
gpt4 key购买 nike

无法在使用ubuntu的终端上运行用c编写的mpi代码

karim@karim:~/Desktop/greetings$ mpicc main.c -o test
karim@karim:~/Desktop/greetings$ mpirun -np 3 test
mpiexec_karim: cannot connect to local mpd (/tmp/mpd2.console_karim); possible causes:
1. no mpd is running on this host
2. an mpd is running but was started without a "console" (-n option)
In case 1, you can start an mpd on this host with:
mpd &

and you will be able to run jobs just on this host.
For more details on starting mpds on a set of hosts, see
the MPICH2 Installation Guide.

#include <stdio.h>
#include <string.h>
#include "mpi.h"
int main(int argc , char * argv[])
{
int my_rank; /* rank of process */
int p; /* number of process */
int source; /* rank of sender */
int dest; /* rank of reciever */
int tag = 0; /* tag for messages */
char message[100]; /* storage for message */
MPI_Status status; /* return status for recieve */

/* Start up MPI */
MPI_Init( &argc , &argv );

/* Find out process rank */
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

/* Find out number of process */
MPI_Comm_size(MPI_COMM_WORLD, &p);

if( my_rank != 0)
{
/* create message */
sprintf( message, "Greetings from process %d !",my_rank);
dest = 0;
/* use Strlen+1 to transmit /0 */
MPI_Send( message, strlen(message)+1, MPI_CHAR, dest, tag,
MPI_COMM_WORLD);
}else
{
for( source = 1; source < p ; source++)
{
MPI_Recv(message, 100, MPI_CHAR, source, tag, MPI_COMM_WORLD,
&status);
printf("%s\n" , message);
}
}
/* shutdown MPI */
MPI_Finalize();
return 0;
}

输出:

Greetings from process 1 !
Greetings from process 2 !
Greetings from process 3 !

最佳答案

经过搜索我通过这段代码解决了问题

mpd --ncpus=2 &
mpirun -np 2 --host localhost ./try.exe

关于c - 如何在 mpi : cannot connect to local mpd (/tmp/mpd2. console_karim 中运行 C 代码);可能的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55764035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com