0
我在通过包含两个节点的群集上运行MPI程序(用C或C++编写)时遇到问题。 详细信息: 操作系统:Ubuntu 16.04 节点数:2(主从)在MPI群集上运行C程序
一切正常。当我和12簇作为参数上运行一个简单mpi_hello程序(没有。的过程)我看到(选中使用顶部)4 从节点上运行的MPI-你好实例。当我尝试运行另一个程序(例如计算和打印范围中的素数的简单程序)时,它在主节点上运行,但在从节点上看不到它的任何实例。
#include <stdio.h>
#include<time.h>
//#include</usr/include/c++/5/iostream>
#include<mpi.h>
int main(int argc, char **argv)
{
int N, i, j, isPrime;
clock_t begin = clock();
int myrank, nprocs;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
printf("Hello from the processor %d of %d \n" , myrank, nprocs);
printf("To print all prime numbers between 1 to N\n");
printf("Enter the value of N\n");
scanf("%d",&N);
/* For every number between 2 to N, check
whether it is prime number or not */
printf("Prime numbers between %d to %d\n", 1, N);
for(i = 2; i <= N; i++){
isPrime = 0;
/* Check whether i is prime or not */
for(j = 2; j <= i/2; j++){
/* Check If any number between 2 to i/2 divides I
completely If yes the i cannot be prime number */
if(i % j == 0){
isPrime = 1;
break;
}
}
if(isPrime==0 && N!= 1)
printf("%d ",i);
}
clock_t end = clock();
double time_spent = (double)(end - begin)/CLOCKS_PER_SEC;
printf("\nThe time spent by the program is %f\n" , time_spent);
while(1)
{}
MPI_Finalize();
return 0;
}
可能是什么它背后可能的原因? 有没有其他的方法来检查它是否在从节点上运行? 谢谢
我不会感到惊讶,这是由于'stdin'没有连接到所有MPI进程。试着摆脱'scanf()'并将该值作为命令行参数传递。 – Gilles
感谢吉尔,我现在对程序中的值进行了硬编码。它显示在第二个节点上工作。但我没有看到任何优势。与使用MPI并行运行时相比,在不使用MPI的情况下在单个节点上运行相同的程序更快(占用一半时间)。也许我没有正确实施并行。你能指出代码中的任何问题吗?代码与上面相同......感谢 – shaibi
没有工作共享到您的代码中:您不会将工作分配到MPI进程中;所有流程都涉及到整个工作。因此,没有机会获得任何加速。 – Gilles