You are on page 1of 3

// ConsoleApplication10.cpp : Defines the entry point for the console application.

//
#include
#include
#include
#include

"stdafx.h"
"mpi.h"
"stdio.h"
"stdlib.h"

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


{
int mynodes, totalnodes;
MPI_Init(&argc, &argv);
printf("HELLO WORLD \n");
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
MPI_Comm_rank(MPI_COMM_WORLD, &mynodes);
printf("TOTAL NUMBER OF NODES : - %d", &totalnodes);
printf("\nMY NODE : - %d", &mynodes);
/*int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
char helloStr[] = "HELLO WORLD";
MPI_Send(helloStr, _countof(helloStr), MPI_CHAR, 1, 0, MPI_COMM_WORLD);
}
else if (rank == 1)
{
char helloStr[12];
MPI_Recv(helloStr, _countof(helloStr), MPI_CHAR, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Rank 1 recevied string %s from Rank 0\n", helloStr);
}*/
MPI_Finalize();
return 0;
}

#include<iostream>
#include "stdafx.h"
#include "mpi.h"
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char ** argv)
{
int mynode, totalnodes;
int sum, startval, endval, accum;

MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes); // get totalnodes
MPI_Comm_rank(MPI_COMM_WORLD, &mynode); // get mynode
sum = 0; // zero sum for accumulation
startval = 1000 * mynode / 5;
endval = 1000 * (mynode + 1) / 4;
for (int i = startval; i <= endval; i = i + 1)
{
sum = sum + i;
//if (i == (endval - 2))
//printf("The Processor is : - %d", &j);
}
if (mynode != 0)
{
MPI_Send(&sum, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
printf("The Processor is : - %d", &mynode);
}
else
for (int j = 1; j<totalnodes; j = j + 1)
{
MPI_Recv(&accum, 1, MPI_INT, j, 1, MPI_COMM_WORLD, &status);
sum = sum + accum;
}
if (mynode == 0)
printf("The sum from 1 to 1000 is: %d", &sum);
}

MPI_Finalize();

#include<iostream>
#include "stdafx.h"
#include "mpi.h"
#include "stdio.h"
#include "stdlib.h"
//using namespace std;
int main(int argc, char ** argv)
{
//("HELLO WORLD \n");
int mynode, totalnodes;
int i = 10;

printf("%d", i);
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes); // get totalnodes
MPI_Comm_rank(MPI_COMM_WORLD, &mynode); // get mynode
printf("Hello world from process rank(number): %d from %d\n", mynode, totalnodes );
//cout << "Hello world from process " << mynode << " out of " << totalnodes;

MPI_Finalize();
return 0;

You might also like