-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Requirement: | ||
OpenMPI, mpi4py for parent.py | ||
|
||
Compilation: | ||
mpifort -o worker -fopenmp worker.f | ||
|
||
Execution: | ||
mpiexec -n 1 python parent.py : -n 1 worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from mpi4py import MPI | ||
import numpy as np | ||
|
||
# MPI initialization | ||
comm = MPI.COMM_WORLD | ||
|
||
# Send array to Fortran code | ||
comm.Send([np.array([[10,11],[12,13]],dtype='i4'), MPI.INT], dest=1, tag=3) | ||
|
||
# Send array to Fortran code | ||
#comm.Send([np.array([[10,11],[12,13]],dtype='i4',order='F'), MPI.INT], dest=1, tag=3) | ||
|
||
#arr[0][0] = 10 | ||
#arr[0][1] = 11 | ||
#arr[1][0] = 12 | ||
#arr[1][1] = 13 | ||
|
||
# MPI Finalize | ||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use mpi | ||
use omp_lib | ||
implicit none | ||
|
||
integer ierr,comm,i,j | ||
integer arr(2,2) | ||
real*8 num | ||
! MPI initialization | ||
call MPI_INIT(ierr) | ||
comm = MPI_COMM_WORLD | ||
|
||
! Receive array from Python code | ||
call MPI_RECV(arr,4,MPI_INT,0,3,comm,MPI_STATUS_IGNORE,ierr) | ||
do i=1,2 | ||
do j=1,2 | ||
write(*,*) arr(i,j) | ||
enddo | ||
enddo | ||
|
||
! MPI Finalize | ||
call MPI_FINALIZE(ierr) | ||
return | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from mpi4py import MPI | ||
import numpy as np | ||
|
||
# MPI initialization | ||
comm = MPI.COMM_WORLD | ||
rank = comm.Get_rank() | ||
print('Python rank: ' + str(rank)) | ||
|
||
# Send integer to Fortran code | ||
comm.Send([np.array([12489],dtype='i4'), MPI.INT], dest=1, tag=1) | ||
|
||
# Receive double from Fortran code | ||
num = np.array([0.],dtype='f8') | ||
comm.Recv([num, MPI.DOUBLE], source=1, tag=2) | ||
print('Python receives: ' + str(num)) | ||
|
||
# MPI Finalize | ||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use mpi | ||
use omp_lib | ||
implicit none | ||
|
||
integer ierr,var,comm,rank,i | ||
real*8 num | ||
! MPI initialization | ||
call MPI_INIT(ierr) | ||
comm = MPI_COMM_WORLD | ||
call MPI_COMM_RANK(comm, rank, ierr) | ||
write(*,*) 'Fortran rank: ',rank | ||
|
||
! Receive integer from Python code and print it | ||
call MPI_RECV(var,1,MPI_INT,0,1,comm,MPI_STATUS_IGNORE,ierr) | ||
write(*,*) 'Fortran receives: ',var | ||
|
||
! Send double to Python code | ||
num = 3.d6 | ||
call MPI_SEND(num,1,MPI_DOUBLE_PRECISION,0,2,comm,ierr) | ||
|
||
! OpenMP in Fortran code | ||
call omp_set_num_threads(4) | ||
!$OMP PARALLEL DO | ||
do i=1,4 | ||
write(*,*) 'Fortran OpenMP: ',i | ||
enddo | ||
!$OMP END PARALLEL DO | ||
|
||
! MPI Finalize | ||
call MPI_FINALIZE(ierr) | ||
return | ||
end |