MPI and OpenMP
//MPI and processes
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "mpi.h"
int main( int argc, char *argv[] )
{
int rank;
int size;
int x=5;
printf( "Hello world from process %d x=%d\n", getpid(),x);
/* MPI_Comm_rank(MPI_COMM_WORLD, &rank); Error 1 */
MPI_Init( NULL, NULL );
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
x=rank;
printf( "Hello world from process %d x=%d\n", getpid(),x);
MPI_Finalize();
/* MPI_Comm_rank(MPI_COMM_WORLD, &rank); Error 2 */
printf( "Hello world from process %d x=%d\n", getpid(),x);
return 0;
}
Error 1
Error 2
//Just Hello
#include <stdio.h>
#include <unistd.h> /* getpid() */
/*#include "mpi.h"*/
int main( int argc, char *argv[] )
{
printf( "Hello from process %d.\n",getpid());
return 0;
}
//OpenMPI and threads
#include <stdio.h>
#include <omp.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char* argv[]){
printf("Hello-Before from thread %d of process %d\n",omp_get_thread_num(),getpid());
{
#pragma omp parallel num_threads(4)
printf("Hello-During from thread %d of process %d\n",omp_get_thread_num(),getpid());
}
printf("Hello-After from thread %d of process %d\n",omp_get_thread_num(),getpid());
return 0;
}