Параллельные вычисления в ИММ УрО РАН
 
 

Назад

 

В начало

Далее

Запуск на нескольких процессорах с использованием mpi

Приведем пример компиляции и запуска программы, на писанной на Фортране 90. Пример взят из комплекта поставки системы программирования на МВС 1000/16 (um16). В примере демонстрируется использование процедур mpi из пакета mpi (связь с ним обеспечивается добавлением в bash_profile к команде "PATH" еще одного элемента списка доступных библиотек : /usr/local/mpich1.2.2.2/bin).

 Для mpi компилируем программы на f90 с помощью пускателя mpif90 командой

mpif90 -o pi3f90 pi3f90.f90

Ниже приведенная программа находится в файле pi3f90.f90

!**********************************************************************

! pi3f90.f - compute pi by integrating f(x) = 4/(1 + x**2)

!

! Each node:

! 1) receives the number of rectangles used in the approximation.

! 2) calculates the areas of it's rectangles.

! 3) Synchronizes for a global summation.

! Node 0 prints the result.

!

! Variables:

!

! pi the calculated result

! n number of points of integration.

! x midpoint of each rectangle's interval

! f function to integrate

! sum,pi area of rectangles

! tmp temporary scratch space for global summation

! i do loop index

!****************************************************************************

program main

use mpi

double precision PI25DT

parameter (PI25DT = 3.141592653589793238462643d0)

 

double precision mypi, pi, h, sum, x, f, a

integer n, myid, numprocs, i, rc

! function to integrate

f(a) = 4.d0 / (1.d0 + a*a)

 

call MPI_INIT( ierr )

call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )

call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )

print *, 'Process ', myid, ' of ', numprocs, ' is alive'

 

sizetype = 1

sumtype = 2

 

do

if ( myid .eq. 0 ) then

write(6,98)

98 format('Enter the number of intervals: (0 quits)')

read(5,99) n

99 format(i10)

endif

 

call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)

 

! check for quit signal

if ( n .le. 0 ) exit

 

! calculate the interval size

h = 1.0d0/n

 

sum = 0.0d0

do i = myid+1, n, numprocs

x = h * (dble(i) - 0.5d0)

sum = sum + f(x)

enddo

mypi = h * sum

 

! collect all the partial sums

call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0, &

MPI_COMM_WORLD,ierr)

 

! node 0 prints the answer.

if (myid .eq. 0) then

write(6, 97) pi, abs(pi - PI25DT)

97 format(' pi is approximately: ', F18.16, &

' Error is: ', F18.16)

endif

 

enddo

 

call MPI_FINALIZE(rc)

stop

end

 После трансляции получаем сообщение

[u1317@rscu_1 f90exampl]$ mpif90 -o pi3f90 pi3f90.f90

program MAIN

 

parameter (PI25DT = 3.141592653589793238462643d0)

^

Warning 101 at (25:pi3f90.f90) : Constant truncated -- precision too great

 

f(a) = 4.d0 / (1.d0 + a*a)

^

Comment 18 at (30:pi3f90.f90) : The statement function is obsolescent in Fortran

95

 

sum = sum + f(x)

^

Comment 18 at (59:pi3f90.f90) : The statement function is obsolescent in Fortran

95

 

82 Lines Compiled

Press any key to continue...

 

Предупреждающие сообщения не помешали компилятору изготовить файлы - объектный pi3f90.o и выполняемый pi3f90

 

Запускается выполняемый файл командой

 

Mpirun np 2 time=3 pi3f90

 

Программа запускается и создает файлы pi3f90.img, mpimod.pc, каталог np.1

В этом каталоге созданы файлы manager.log, output, runmvs.bat

 

В файле output содержится информация

call_batch: calling batch

/common/mpich/bin/mpirun -p4pg /tmp/proclist.yjs9rF /home/u1317/f90exampl/np 2 t

Warning: Command line arguments for program should be given

after the program name. Assuming that 2 is a

command line argument for the program.

Warning: Command line arguments for program should be given

after the program name. Assuming that time=3 is a

command line argument for the program.

Unrecognized argument /home/u1317/f90exampl/np ignored.

Process 0 of 1 is alive

Enter the number of intervals: (0 quits)

 

Input/Output Error 153: Input file ended

 

In Procedure: main program

At Line: 44

 

Statement: Formatted READ

Unit: 5

Connected To: Stdin

Form: Formatted

Access: Sequential

Records Read : 0

Records Written: 0

P4 procgroup file is /tmp/proclist.yjs9rF.

/common/mpich/bin/mpirun: line 1: 20085 Segmentation fault (core dumped) /h

 

Результат правильный с учетом того, что программа требует ввода.

     Назад

 

В начало

Далее