1Using MPIFX
2===========
3
4Before you can use the MPIFX routines you need the following steps:
5
6#. Use the module `libmpifx_module` in your routines.
7
8#. Initialize the MPI framework via the `mpifx_init()` routine. (If you already
9   initialized it via the legacy `mpi_init()` call, you can omit this step.
10
11#. Initialize a communicator of `type(mpifx_comm)`.
12
13Below you find a self containing example for reduction on all processes using
14a wrapper around `mpi_allreduce()`::
15
16    program test_allreduce
17      use libmpifx_module
18      implicit none
19
20      integer, parameter :: dp = kind(1.0d0)
21
22      type(mpifx_comm) :: mycomm
23      integer :: vali0, resvali0
24      real(dp) :: valr(3), resvalr(3)
25
26      call mpifx_init()
27      call mycomm%init()
28
29      ! Reduce scalar value
30      vali0 = mycomm%rank * 2  ! Some arbitrary number
31      write(*, "(I2.2,'-',I3.3,'|',1X,A,I0)") 1, mycomm%rank, &
32          & "Value to be operated on:", vali0
33      call mpifx_allreduce(mycomm, vali0, resvali0, MPI_SUM)
34      write(*, "(I2.2,'-',I3.3,'|',1X,A,I0)") 2, mycomm%rank, &
35          & "Obtained result (sum):", resvali0
36
37      ! Reduce vector
38      valr(:) = [ real(mycomm%rank + 1, dp) * 1.2, &
39          & real(mycomm%rank + 1, dp) * 4.3, real(mycomm%rank + 1, dp) * 3.8 ]
40      write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 3, mycomm%rank, &
41          & "Value to be operated on:", valr(:)
42      call mpifx_allreduce(mycomm, valr, resvalr, MPI_PROD)
43      write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 4, mycomm%rank, &
44          & "Obtained result (prod):", resvalr(:)
45      call mpifx_finalize()
46
47    end program test_allreduce
48
49
50When running on 4 processors::
51
52    mpirun -n 4 test_allreduce | sort
53
54you should obtain the following output::
55
56    01-000| Value to be operated on:0
57    01-001| Value to be operated on:2
58    01-002| Value to be operated on:4
59    01-003| Value to be operated on:6
60    02-000| Obtained result (sum):12
61    02-001| Obtained result (sum):12
62    02-002| Obtained result (sum):12
63    02-003| Obtained result (sum):12
64    03-000| Value to be operated on:    1.20    4.30    3.80
65    03-001| Value to be operated on:    2.40    8.60    7.60
66    03-002| Value to be operated on:    3.60   12.90   11.40
67    03-003| Value to be operated on:    4.80   17.20   15.20
68    04-000| Obtained result (prod):   49.77 8205.12 5004.33
69    04-001| Obtained result (prod):   49.77 8205.12 5004.33
70    04-002| Obtained result (prod):   49.77 8205.12 5004.33
71    04-003| Obtained result (prod):   49.77 8205.12 5004.33
72
73Have a look at the test folder in the source tree for further examples.
74