Using open MPI in a part of the code

Pavel

I am writing a Fortran 95 code (with gfortran as a compiler). In one of the subroutines, I initialize the Message Passing Interface by calling MPI_Init. I close the interface by calling MPI_Finalize in the same subroutine. Neither in the main program nor in any other subroutines do I use MPI commands.

The code is running well; however, every WRITE(*,*) "text" statement in the main program is executed twice when I run the code (I am testing the code on my laptop with two physical cores). So it seems that both cores are processing all the commands of the main program.

Is this what one should expect? What is the right way of initializing and finalizing the MPI?

I would like one core to process all the sequential tasks and use multicore processing only in the subroutine.

Alexander Vogt

Well, this is more an extended comment than an answer...

With MPI the program is executed once for each process (in your case twice), and you have to make sure which process executes which code or operates on which chunk of data. This is usually done by determining the rank of the process by calling MPI_Comm_rank(). Based on the rank and the number of processes obtained with MPI_Comm_size() you can distribute the workload.

Since you do not do that, each process is doing exactly the same work, and consequently prints the same text onto the terminal.

This is an example to illustrate this:

program test
  use mpi
  implicit none
  integer :: myrank, size, stat

  ! Init MPI
  call MPI_Init(stat)

  ! Get process ID
  call MPI_Comm_rank ( MPI_COMM_WORLD, myrank, stat )
  ! Get number of processes
  call MPI_Comm_size ( MPI_COMM_WORLD, size, stat )

  ! This is only written by the first process
  if ( myrank == 0 ) write(*,*) 'Starting output...'

  ! This is written by every process
  write(*,*) "Hello world"
  write(*,*) "I am ",myrank,"of",size

  call MPI_Finalize(stat)  
end program

With the output:

$ mpirun -np 2 ./a.out
 Starting output...
 Hello world
 Hello world
           I am            1 of           2
           I am            0 of           2

You can see that without the check for the rank of the process, "Hello World" is printed twice.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Open MPI and Boost MPI using too many file handles

From Dev

Open MPI and Boost MPI using too many file handles

From Dev

Using valgrind to spot error in mpi code

From Dev

Running Java code using MPI function

From Dev

How to mix serial and parallel code using MPI

From Dev

Open MPI: using bind-to-core while oversubscribing

From Dev

Open MPI: using bind-to-core while oversubscribing

From Dev

Open MPI ranks are not in order

From Dev

How to open a program using code

From Dev

Using #define directives as "part" of code, not at top of file

From Dev

Can not repeat a part of code in lua using for loop

From Dev

Hybrid MPI/GPU code

From Dev

open part of web page in android using uri intent

From Dev

Open MPI Virtual Timer Expired

From Dev

MPI_Scatterv scatters only part of custom MPI_Datatype

From Dev

Silently open a web browser using Java code

From Dev

Using Loops in MPI

From Dev

Using the default integer in MPI

From Dev

Is there a limit for the message size in mpi using boost::mpi?

From Dev

How to replace an existing file in MPI with MPI_File_open

From Dev

Open MPI's MPI_reduce not combining array sums

From Dev

How to install Open MPI with Cuda-Aware MPI in Linux Debian

From Dev

Open part of a PDF in HTML

From Dev

Static linking of an FORTRAN code with MPI

From Dev

scatter in mpi [a very simple code]

From Dev

How can I perform my part of code using map and match?

From Dev

Mass grabing part of HTML source code using shell scripts

From Dev

Extract part of text from meta using Zapier code action (javascript)

From Dev

Hide / show the part of code using php, if the value contains the letters

Related Related

HotTag

Archive