parallel eclipse does not recognize true number of processors when using MPI

116 views Asked by At

I have the following code that when executed with eclipse 2020.12, the output is this: "Hello from rank 0 out of 1"

#include <iostream>
#include <mpi.h>
using namespace std;

int main(int argc, char* argv[])
{

    MPI_Init(&argc, &argv);

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    int size;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    int data;

    if (rank > 0) {

        MPI_Recv(&data, 1, MPI_INT, rank-1, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);
                cout << "Rank "<< rank<< " has received message with data " << data
                        << " from rank " << rank-1
                        << endl;
    }

    cout << "Hello from rank " << rank<< " out of " << size<< endl;

    if (rank < size-1) {
        data = rank*rank;

        MPI_Send(&data, 1, MPI_INT, rank+1, 0, MPI_COMM_WORLD);
    }

    MPI_Finalize();
    return 0;
}

But, when I execute this through command line with following commands, it works as expected

mpic++ -o name name.cpp
mpiexec -np 4 ./name

it shows 4 hello , which is number of my cores. I was wondering why eclipse cannot recognize but the sampe cpp file with another way of execution works fine! and the output will be :

Hello from rank 0 out of 4
Rank 1 has received message with data 0 from rank 0
Hello from rank 1 out of 4
Rank 2 has received message with data 1 from rank 1
Hello from rank 2 out of 4
Rank 3 has received message with data 4 from rank 2
Hello from rank 3 out of 4
2

There are 2 answers

0
Hristo Iliev On BEST ANSWER

Create a new run configuration from the Parallel Application template. On the Resources tab, set Target System Configuration to Generic OpenMPI Interactive or Generic MPICH2 Interactive based on whether your MPI implementation derives from Open MPI or MPICH. Set Connection Type to Local. Then set the number of processes in the Basic Options tab.

enter image description here

Switch to the Application tab and put the path to the executable file in Application program. Just click the Browse button next of it and navigate to either Debug or Release directory and select the executable there.

enter image description here

The Run button should now turn blue and you can press it.

enter image description here

0
dreamcrash On

Go to the Project and:

  • click with the second mouse button
  • select Run As > Run Configurations
  • select Parallel Applications
  • click with the second mouse button
  • click of new configuration
  • click on the newly create configuration
  • click on Resources
  • from the "Target System Configuration" dropdown menu select for instance "Generic Remote Interactive"
  • in connection type select local (since you will run the eclipse locally)

enter image description here

  • switch to tap Application
  • in application program enter the path to you mpirun e.g., /usr/bin/mpirun

enter image description here

  • finally switch to Arguments
  • in application argument pass the argument "-np 4"

enter image description here

  • click run