... | @@ -195,21 +195,21 @@ module purge |
... | @@ -195,21 +195,21 @@ module purge |
|
|
|
|
|
int main (int argc, char *argv[])
|
|
int main (int argc, char *argv[])
|
|
{
|
|
{
|
|
int id, np, i;
|
|
int id, np, i;
|
|
char processor_name[MPI_MAX_PROCESSOR_NAME];
|
|
char processor_name[MPI_MAX_PROCESSOR_NAME];
|
|
int processor_name_len;
|
|
int processor_name_len;
|
|
|
|
|
|
MPI_Init(&argc, &argv);
|
|
MPI_Init (&argc, &argv);
|
|
|
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &np);
|
|
MPI_Comm_size (MPI_COMM_WORLD, &np);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &id);
|
|
MPI_Comm_rank (MPI_COMM_WORLD, &id);
|
|
MPI_Get_processor_name(processor_name, &processor_name_len);
|
|
MPI_Get_processor_name (processor_name, &processor_name_len);
|
|
|
|
|
|
for (i=1;i<2;i++)
|
|
for (i=1;i<2;i++)
|
|
printf ("Hello world from process %03d out of %03d, processor name %s \n", id, np, processor_name);
|
|
printf ("Hello world from process %03d out of %03d, processor name %s \n", id, np, processor_name);
|
|
|
|
|
|
MPI_Finalize();
|
|
MPI_Finalize ();
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | @@ -218,36 +218,34 @@ int main (int argc, char *argv[]) |
... | @@ -218,36 +218,34 @@ int main (int argc, char *argv[]) |
|
#include "string.h"
|
|
#include "string.h"
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
int main (int argc, char *argv[])
|
|
{
|
|
{
|
|
int numprocs, myrank, namelen, i;
|
|
int numprocs, myrank, namelen, i;
|
|
char processor_name[MPI_MAX_PROCESSOR_NAME];
|
|
char processor_name[MPI_MAX_PROCESSOR_NAME];
|
|
char greeting[MPI_MAX_PROCESSOR_NAME + 80];
|
|
char greeting[MPI_MAX_PROCESSOR_NAME + 80];
|
|
MPI_Status status;
|
|
MPI_Status status;
|
|
|
|
|
|
MPI_Init( &argc, &argv );
|
|
MPI_Init (&argc, &argv);
|
|
MPI_Comm_size( MPI_COMM_WORLD, &numprocs );
|
|
MPI_Comm_size (MPI_COMM_WORLD, &numprocs);
|
|
MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
|
|
MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
|
|
MPI_Get_processor_name( processor_name, &namelen );
|
|
MPI_Get_processor_name (processor_name, &namelen);
|
|
|
|
|
|
sprintf( greeting, "Hello world, from process %d of %d on %s",
|
|
sprintf (greeting, "Hello world, from process %d of %d on %s", myrank, numprocs, processor_name);
|
|
myrank, numprocs, processor_name );
|
|
|
|
|
|
if (myrank == 0)
|
|
if ( myrank == 0 ) {
|
|
{
|
|
printf( "%s\n", greeting );
|
|
printf ("%s\n", greeting);
|
|
for ( i = 1; i < numprocs; i++ ) {
|
|
for (i = 1; i < numprocs; i++ )
|
|
MPI_Recv( greeting, sizeof( greeting ), MPI_CHAR,
|
|
{
|
|
i, 1, MPI_COMM_WORLD, &status );
|
|
MPI_Recv (greeting, sizeof (greeting), MPI_CHAR, i, 1, MPI_COMM_WORLD, &status);
|
|
printf( "%s\n", greeting );
|
|
printf ("%s\n", greeting);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else
|
|
MPI_Send( greeting, strlen( greeting ) + 1, MPI_CHAR,
|
|
MPI_Send (greeting, strlen (greeting) + 1, MPI_CHAR, 0, 1, MPI_COMM_WORLD);
|
|
0, 1, MPI_COMM_WORLD );
|
|
|
|
}
|
|
MPI_Finalize ();
|
|
|
|
return 0;
|
|
MPI_Finalize( );
|
|
|
|
return 0;
|
|
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | | ... | |