File: cpi-master.f90

package info (click to toggle)
mpi4py 4.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,540 kB
  • sloc: python: 34,465; ansic: 16,475; makefile: 614; sh: 325; cpp: 193; f90: 178
file content (45 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
PROGRAM main

  USE mpi
  implicit none

  real (kind=8), parameter :: PI = 3.1415926535897931D0

  integer argc
  character(len=32) argv(0:1)

  character(len=32) cmd
  integer ierr, n, worker
  real(kind=8) cpi

  call MPI_INIT(ierr)

  argc = iargc() + 1
  call getarg(0, argv(0))
  call getarg(1, argv(1))

  cmd = './cpi-worker-f90.exe'
  if (argc > 1) then
     cmd = argv(1)
  end if
  write(*,'(A,A,A)') trim(argv(0)), ' -> ', trim(cmd)

  call MPI_COMM_SPAWN(cmd, MPI_ARGV_NULL, 5, &
                      MPI_INFO_NULL, 0, &
                      MPI_COMM_SELF, worker, &
                      MPI_ERRCODES_IGNORE, ierr)

  n = 100
  call MPI_BCAST(n, 1, MPI_INTEGER, &
                 MPI_ROOT, worker, ierr)

  call MPI_REDUCE(MPI_BOTTOM, cpi, 1, MPI_DOUBLE_PRECISION, &
                  MPI_SUM, MPI_ROOT, worker, ierr)

  call MPI_COMM_DISCONNECT(worker, ierr)

  write(*,'(A,F18.16,A,F18.16)') 'pi: ', cpi, ', error: ', abs(PI-cpi)

  call MPI_FINALIZE(ierr)

END PROGRAM main