0

I am learning MPI. I have two Windows machines on each I have VS2015 and I have installed Microsoft HPC Pack 2012, Microsoft HPC Pack 2012 SDK 8.1, Microsoft MPI 8.1 and I am able to run the following code on each machine separately.

I want to connect the two machines to communicate through MPI and run this code while having the ability to specify which process ID runs on which machine. What is the next step to achieve this?

#include<iostream>
#include "mpi.h"
#include <omp.h>

using namespace std;

int numOfProc, id, array_size, portion;
int *arr = NULL;
MPI_Status status;
const static int tag = 1;


int main(int argc, char *argv[])
{
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &numOfProc);
    MPI_Comm_rank(MPI_COMM_WORLD, &id);

    cout << "Hello from Process # " << id << '\n';

    if (id == 0)//master
    {
        cin >> array_size;
        arr = new int[array_size];

        for (int i = 0; i < array_size; i++)
        {
            arr[i] = i + 1;
        }

        portion = array_size / numOfProc;

        for (int p = 1; p < numOfProc; p++)
        {

            MPI_Send(&portion, 1, MPI_INT, p, tag, MPI_COMM_WORLD);
            MPI_Send(&arr[(p - 1)*portion], portion, MPI_INT, p, tag, MPI_COMM_WORLD);
        }
    }
    else // slaves 
    {

        //cout << "Hello from Process # " << id << '\n';

        MPI_Recv(&portion, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);

        arr = new int[portion];

        MPI_Recv(arr, portion, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);


    omp_set_num_threads(2);
#pragma omp parallel for
        for (int i = 0; i < portion; i++)
        {
            cout << "Thread [" << omp_get_thread_num() << "] is printing number " << arr[i] << "." << endl;
        }

    }

    MPI_Finalize();

}
Jack
  • 131
  • 1
  • 8
  • I would treat MPI as a software. Meaning there is minimum requirement before you can run the MPI Application. This also raises the question like can you connect MPI from one OS to another OS i.e in Linux and Windows Or does it support VS 2015 or just VS 2012. – Juniar Jul 08 '17 at 23:10
  • I am trying not to worry about different OS as I intend to use all machines running same OS. As for VS2015 considering I tried it on one machine and it is working with MPI then I am assuming there are no problems with that. – Jack Jul 09 '17 at 05:30
  • I want to know what is the next step in configuring a cluster of machines to communicate together and run some application. – Jack Jul 09 '17 at 08:19
  • Okay, so that is what MPI does. Concurrently running applications with multiple processors. And you already have one processor or machine and you intend to invoke another machine to make your load be processed concurrently and more efficient. I would check if there are any documentations about this or a sample code. – Juniar Jul 09 '17 at 21:13
  • I have some MPI Tools and related links: http://www.mcs.anl.gov/research/projects/mpi/ and also for the tools that you might require: http://www.mcs.anl.gov/research/projects/mpi/tools.html – Juniar Jul 09 '17 at 21:49
  • Thank you very much, Juniar, much appreciated. – Jack Jul 10 '17 at 08:23

0 Answers0