-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many additions to parallel course, a few to Fortran
- Loading branch information
Showing
97 changed files
with
3,251 additions
and
457 deletions.
There are no files selected for viewing
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,73 @@ | ||
program printit | ||
implicit none | ||
|
||
integer, parameter :: rk=kind(1.0) | ||
integer, parameter :: dk=kind(1.d0) | ||
|
||
complex :: z | ||
real(rk) :: rpi=4.0*atan(1.0) | ||
real(rk) :: dpi=4.d0*atan(1.d0) | ||
real(rk) :: res | ||
integer :: i,j | ||
integer :: i1=42, i2=99 | ||
logical :: is_zero, is_finite | ||
character(len=12) :: mess1, mess2 | ||
|
||
real(rk), dimension(4) :: b | ||
real(rk), dimension(4,4) :: arr | ||
|
||
res=cos(rpi) | ||
|
||
do i=1,size(arr,1) | ||
b(i)=real(i) | ||
do j=1,size(arr,2) | ||
arr(i,j)=real(i+j) | ||
enddo | ||
enddo | ||
|
||
z=cmplx(res,rpi) | ||
|
||
mess1="First result" | ||
mess2="An integer" | ||
|
||
is_zero=.false. | ||
is_finite=.true. | ||
|
||
write(*,'(i5,2x,i6)') i1,i2 | ||
write(*,'(i5,a,i6)') i1," ",i2 | ||
write(*,'(a,f0.6)') "The result is ",res | ||
write(*,'(a,i4,es15.7)') "The answer",i1,dpi | ||
write(*,'(4(i2,3x,f8.3))') (j,b(j),j=1,4) | ||
write(*,'(2f8.2)') z !complex | ||
write(*,'(2L)')is_zero,is_finite | ||
write(*,'(2p,f8.2,0p,f8.2)') rpi, dpi | ||
write(*,'(a,f8.2,/,a,i6)') mess1,res,mess2,i1 | ||
write(*,'(a)') ' ' | ||
write(*,'("first value ",f8.2,", second value ",i6)') res | ||
write(*,'(a)') ' ' | ||
write(*,'("first value ",f8.2,:," second value ",i6)') res | ||
|
||
write(*,*) '----------------------' | ||
|
||
do i=1,size(arr,1) | ||
write(*,'(*(g0))') arr(i,:) | ||
enddo | ||
|
||
write(*,*) '----------------------' | ||
|
||
do i=1,size(arr,1) | ||
write(*,'(*(f12.4))') arr(i,:) | ||
enddo | ||
|
||
! Old style | ||
WRITE ( *, 2 ) i1 | ||
WRITE ( *, 2 ) i1,i2 | ||
2 FORMAT ( 1X 'RESULT = ', I2, :, 3X, 'AT INDEX = ', I2 ) | ||
|
||
write(*,*) | ||
|
||
write(*,'(f8.2)',advance='no') res | ||
write(*,'(i6)',advance='yes') i2 | ||
write(*,*) 'All done' | ||
|
||
end program |
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
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
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
content/courses/parallel-computing-introduction/codes/contour.py
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,21 @@ | ||
import sys | ||
import argparse | ||
import glob | ||
import numpy as np | ||
import pylab as plt | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-f", "--fortran", help="Fortran ordering", action="store_true") | ||
parser.add_argument("filename", help="output file name") | ||
args = parser.parse_args() | ||
base = args.filename | ||
|
||
data=np.loadtxt(args.filename,unpack=False) | ||
|
||
if args.fortran: | ||
data.T | ||
|
||
fig=plt.figure() | ||
plt.contourf(data) | ||
plt.colorbar() | ||
plt.show() |
37 changes: 37 additions & 0 deletions
37
content/courses/parallel-computing-introduction/codes/contour_ranks.py
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,37 @@ | ||
import sys | ||
import argparse | ||
import glob | ||
import numpy as np | ||
import pylab as plt | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-f", "--fortran", help="Fortran ordering", action="store_true") | ||
parser.add_argument("filename", help="base name of the output files") | ||
args = parser.parse_args() | ||
base = args.filename | ||
endpos=len(base) | ||
|
||
files=glob.glob(base+"*") | ||
numbers=[] | ||
suffixes=[] | ||
for file in files: | ||
suffix=file[endpos:] | ||
numbers.append(int(suffix)) | ||
suffixes.append(suffix) | ||
|
||
pvec = np.argsort(numbers) | ||
|
||
arrays=[] | ||
for n in pvec: | ||
fname=files[n] | ||
arrays.append(np.loadtxt(fname,unpack=False)) | ||
|
||
if args.fortran: | ||
data=np.concatenate(arrays,axis=1) | ||
else: | ||
data=np.concatenate(arrays,axis=0) | ||
|
||
fig=plt.figure() | ||
plt.contourf(data) | ||
plt.colorbar() | ||
plt.show() |
39 changes: 39 additions & 0 deletions
39
content/courses/parallel-computing-introduction/codes/exchange_deadlock.cxx
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,39 @@ | ||
#include <iostream> | ||
#include <mpi.h> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char **argv) { | ||
|
||
int rank, nprocs, message, neighbor; | ||
MPI_Status status; | ||
|
||
MPI_Init(&argc, &argv); | ||
MPI_Comm_size(MPI_COMM_WORLD, &nprocs); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
|
||
if (nprocs < 2) { | ||
cout<<"This program works only for at least two processes\n"; | ||
MPI_Finalize(); | ||
return 1; | ||
} | ||
else if (nprocs%2 != 0) { | ||
cout<<"This program works only for an even number of processes\n"; | ||
MPI_Finalize(); | ||
return 2; | ||
} | ||
|
||
if (rank%2==0) { | ||
neighbor = rank+1; | ||
} | ||
else { | ||
neighbor = rank-1; | ||
} | ||
|
||
MPI_Recv(&message, 1, MPI_INT, neighbor, 0, MPI_COMM_WORLD, &status); | ||
MPI_Send(&rank, 1, MPI_INT, neighbor, 0, MPI_COMM_WORLD); | ||
cout<<rank<<" "<<message<<endl; | ||
MPI_Finalize(); | ||
|
||
return 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
content/courses/parallel-computing-introduction/codes/exchange_deadlock.f90
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,37 @@ | ||
program exchange | ||
use mpi | ||
implicit none | ||
|
||
integer :: rank, nprocs, neighbor, ierr | ||
integer :: status(MPI_STATUS_SIZE) | ||
integer :: message | ||
|
||
call MPI_Init(ierr) | ||
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr) | ||
call MPI_Comm_size(MPI_COMM_WORLD, nprocs, ierr) | ||
|
||
if (nprocs < 2) then | ||
write(6,*) "This program works only for at least two processes" | ||
call MPI_Finalize(ierr) | ||
stop | ||
else if ( mod(nprocs,2) /= 0 ) then | ||
write(6,*) "This program works only for an even number of processes" | ||
call MPI_Finalize(ierr) | ||
stop | ||
end if | ||
|
||
if ( mod(rank,2) == 0) then | ||
neighbor = rank+1 | ||
else | ||
neighbor = rank-1 | ||
end if | ||
|
||
call MPI_Recv(message, 1, MPI_INTEGER, neighbor, 0, MPI_COMM_WORLD, status, ierr) | ||
call MPI_Send(rank,1, MPI_INTEGER, neighbor, 0, MPI_COMM_WORLD, ierr) | ||
|
||
write(*,*) rank, message | ||
|
||
call MPI_Finalize(ierr) | ||
|
||
end program | ||
|
27 changes: 27 additions & 0 deletions
27
content/courses/parallel-computing-introduction/codes/exchange_deadlock.py
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,27 @@ | ||
import sys | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
comm=MPI.COMM_WORLD | ||
nprocs=comm.Get_size() | ||
rank=comm.Get_rank() | ||
|
||
if nprocs<2: | ||
print("This program works only for at least two processes.") | ||
sys.exit() | ||
elif nprocs%2!=0: | ||
print("This program works only for an even number of processes.") | ||
sys.exit() | ||
|
||
message=np.zeros(1,dtype='int') | ||
rank_val=rank*np.ones(1,dtype='int') | ||
|
||
if rank%2==0: | ||
neighbor=rank+1 | ||
else: | ||
neighbor=rank-1 | ||
|
||
comm.Recv([message,MPI.INT],source=neighbor) | ||
comm.Send([rank_val,MPI.INT],dest=neighbor) | ||
|
||
print(rank,message) |
Oops, something went wrong.