Compiling a code to run parallel

In summary: You can also change the compiler name to "mpif77/mpif90" if necessary. Additionally, you may need to adjust the FFLAGS and LDFLAGS for the parallelization to work properly.
  • #1
Useful nucleus
370
58
I'm working with a Fortran code which I run on a Linux cluster. I'm able to compile it such that it works fine on one CPU, but I would like to run it parallel . The code manual mention the following as an instruction to compile it to work in parallel
If you wish to run the program in parallel using MPI then you will need to alter the file
"getmachine" accordingly. The usual changes would be to add the "-DMPI" option and in
some cases change the compiler name (for example to mpif77/mpif90).
The get machine file is just a long if statement that tries to get the type of the machine and the type of the fortran compiler on this machine. Since my Machine is Linux with intel compiler , I copy the part of the getmachine file relavant to my machine/compiler

Code:
makedir()
{
  if [ ! -d "$dir" ]
  then
    mkdir "$dir"
  fi
  cd $dir
}

debug=
if [ "$1" = "-debug" ]
then
  debug="_DEBUG"
  shift
fi
os=`uname -s`
case $os in

#
# This is Linux with f90. cdabs.f contains the cdabs function
# which is missing in the f2c library
#
  Linux)   dir="${os}${debug}"
	   makedir
	   if [ "$debug" = "" ]
	   then
# PG compiler
#	       echo 'OPT=-fast -tp=p6 > makefile
#	       echo 'OPT1=-O1 -tp=p6 >> makefile
# Intel compiler
	       echo 'OPT=-O3 -mp1 ' > makefile
	       echo 'OPT1=-O1' >> makefile
	       echo 'OPT2=-O3 -mp1 ' > makefile
# Absoft compiler
#	       echo 'OPT=-O' > makefile
#	       echo 'OPT1=-O' >> makefile
#
	       echo 'BAGGER=' >> makefile
	   else	
	       echo 'OPT=' > makefile
               echo 'BAGGER=-g ' >> makefile
	   fi
           target=${1}_
# PG compiler
#  	   echo 'RUNF90=pgf90 -Bstatic' >> makefile
# Intel compiler
  	   echo 'RUNF90=ifort ' >> makefile
# Absoft compiler
#           echo 'RUNF90=f90' >> makefile
# PG compiler
#	   echo 'FFLAGS=-I.. -DLINUX -Mextend' >> makefile
#	   echo 'LIBS=' >> makefile
# Intel compiler
	   echo 'FFLAGS=-I.. -DLINUX -132' >> makefile
	   echo 'LIBS=' >> makefile
# Absoft compiler
#           echo 'FFLAGS=-I.. -DLINUX -B18 -W132' >> makefile
#           echo 'LIBS=-lblas -lU77' >> makefile
#
           echo 'CFLAGS=-ansi -DLINUX' >> makefile
# PG compiler
#	   echo 'LDFLAGS=-Bstatic' >> makefile
# Intel compiler
	   echo 'LDFLAGS=-static' >> makefile
           echo 'ETIME=' >> makefile
           echo 'BLAS=blas.o' >> makefile
           echo 'LAPACK=lapack.o' >> makefile
           echo 'GULPENV=' >> makefile
	   echo 'CDABS=cdabs.o' >> makefile
           echo 'DEFS=-DLINUX' >> makefile
           ;;

Based on this can somebody please help me in how to modify this file to do the parallelization?
 
Technology news on Phys.org
  • #2
To modify the getmachine file for parallelization, you can add the "-DMPI" option to the OPT and OPT1 lines in the Linux section. For example: # Intel compilerecho 'OPT=-O3 -mp1 -DMPI' > makefileecho 'OPT1=-O1 -DMPI' >> makefileecho 'OPT2=-O3 -mp1 -DMPI' > makefile
 
  • #3


I can provide some guidance on how to modify the "getmachine" file to run your Fortran code in parallel using MPI. First, you will need to add the "-DMPI" option to the compiler. This will allow the code to use MPI commands for parallel processing. Next, you will need to change the compiler name to one that is compatible with MPI, such as "mpif77" or "mpif90". This will ensure that the code is compiled with the necessary libraries for MPI.

Additionally, you will need to make changes to the options and flags in the "makefile" to enable parallel processing. This may include adding options for distributed memory parallelization, such as "-D_PMPI" or "-D_MPI", and changing the target name to include the number of processors to be used.

You may also need to modify the "RUNF90" command to specify the number of processors to be used and to include any necessary MPI libraries. Finally, make sure to set the "GULPENV" variable to include any necessary environment variables for parallel processing.

It may be helpful to consult the manual for your specific Fortran code to ensure that all necessary changes are made to enable parallel processing. You may also want to consult with your colleagues or the developers of the code for additional guidance and support.
 

1. What is parallel computing?

Parallel computing is a method of computer processing in which multiple tasks are executed simultaneously, rather than sequentially. This can greatly increase the speed and efficiency of certain programs, particularly those that involve large amounts of data or complex calculations.

2. Why would I need to compile a code to run parallel?

Compiling a code to run parallel allows it to take advantage of the capabilities of multiple processors or cores in a computer. This can significantly speed up the execution of the code and make it more efficient.

3. How do I know if my code is suitable for parallel computing?

Not all codes are suitable for parallel computing. Generally, codes that involve a lot of independent operations or large amounts of data are good candidates for parallelization. It is important to analyze your code and determine which parts can be parallelized before attempting to compile it for parallel execution.

4. What are some common programming languages used for parallel computing?

Some commonly used programming languages for parallel computing include C, C++, Java, Python, and Fortran. These languages have libraries and tools specifically designed for parallel programming, making it easier to compile code for parallel execution.

5. What are some common challenges when compiling code for parallel execution?

Some common challenges when compiling code for parallel execution include managing data dependencies, ensuring proper synchronization between parallel processes, and dealing with load imbalance. It is important to carefully plan and test the parallelized code to avoid these issues and ensure optimal performance.

Back
Top