Skip to content

Commit cd97006

Browse files
committed
separate out coarray tests
1 parent 3ad97de commit cd97006

File tree

6 files changed

+101
-74
lines changed

6 files changed

+101
-74
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.pytest_cache/
12
bin/
23

34
# Byte-compiled / optimized / DLL files

CMakeLists.txt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.7)
22
project(lineclip Fortran)
33
enable_testing()
44

5-
add_compile_options(-O3 -mtune=native -g)
5+
add_compile_options(-O3 -g)
66

77
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
8-
add_compile_options(-Wall -Wextra -Wpedantic -Werror=array-bounds -fbacktrace -fexceptions)
8+
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 8.1)
9+
list(APPEND FFLAGS -std=f2018)
10+
else()
11+
list(APPEND FFLAGS -std=f2008ts)
12+
endif()
13+
14+
list(APPEND FFLAGS -mtune=native -Wall -Wextra -Wpedantic -Werror=array-bounds -fbacktrace -fexceptions)
915
if(NOT CYGWIN AND NOT WIN32)
10-
add_compile_options(-fstack-protector-all)
16+
list(APPEND FFLAGS -fstack-protector-all)
1117
endif()
18+
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Flang)
19+
link_libraries(-static-flang-libs)
1220
endif()
1321

14-
22+
# TODO should be able to run coarrays demo even in single case, may be algorithmic error in my Coarray demo code?
23+
set(DEMO_COARRAYS FALSE)
1524
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
1625
add_compile_options(-coarray=shared)# -check all)
1726
link_libraries(-coarray=shared)
27+
set(DEMO_COARRAYS TRUE)
1828
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
1929
find_package(OpenCoarrays)
2030

2131
if(OpenCoarrays_FOUND)
2232
list(APPEND OpenCoarrays_LIBRARIES caf_mpi)
23-
add_compile_options(-fcoarray=lib)
33+
list(APPEND FFLAGS -fcoarray=lib)
34+
set(DEMO_COARRAYS TRUE)
2435
else()
25-
add_compile_options(-fcoarray=single)
36+
list(APPEND FFLAGS -fcoarray=single)
2637
endif()
27-
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Flang)
28-
link_libraries(-static-flang-libs)
2938
endif()
3039

3140
add_library(lineclip lineclipping.f90)
32-
target_link_libraries(lineclip)
3341

34-
add_executable(RunLineclip DemoLineclip.f90 assert.f90)
35-
target_link_libraries(RunLineclip PRIVATE lineclip ${OpenCoarrays_LIBRARIES})
42+
add_library(assert assert.f90)
3643

37-
add_test(NAME clip COMMAND ./RunLineclip)
44+
add_executable(RunLineclip DemoLineclip.f90)
45+
target_compile_options(RunLineclip PRIVATE ${FFLAGS})
46+
target_link_libraries(RunLineclip PRIVATE assert lineclip ${OpenCoarrays_LIBRARIES})
47+
add_test(NAME clip COMMAND RunLineclip)
48+
49+
if(DEMO_COARRAYS)
50+
add_executable(CoarrayLineclip DemoCoarrayLineclip.f90)
51+
target_compile_options(CoarrayLineclip PRIVATE ${FFLAGS})
52+
target_link_libraries(CoarrayLineclip PRIVATE assert lineclip ${OpenCoarrays_LIBRARIES})
53+
add_test(NAME CoarrayClip COMMAND cafrun CoarrayLineclip)
54+
endif()

DemoCoarrayLineclip.f90

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
program lineclip
2+
3+
use, intrinsic:: ieee_arithmetic
4+
use lineclip,only: Ccohensutherland, cohensutherland
5+
use assert
6+
7+
implicit none
8+
9+
real(wp) :: L(8)[*]
10+
11+
call coarray_lineclip(L)
12+
! if(this_image()==1) print *,L
13+
14+
contains
15+
16+
subroutine coarray_lineclip(length)
17+
18+
integer, parameter :: Np=8
19+
real(wp), dimension(Np) :: x1,x2,y1,y2
20+
real(wp),parameter :: xmin=1., ymax=5.,xmax=4., ymin=3.
21+
real(wp) :: truelength(Np) =[2.40370083, 3.,0.,0.,0.,0.,2.,2.5]
22+
real(wp) :: nan
23+
integer :: Ni, im, s0,s1
24+
real(wp),intent(out) :: length(Np)[*]
25+
26+
Ni = num_images()
27+
im=this_image()
28+
29+
nan = ieee_value(1.,ieee_quiet_nan)
30+
truelength(3:6) = nan
31+
32+
x1=[0.,0.,0.,0.,0.,0.,0.,0.]
33+
y1=[0.,4.,1.,1.5,2.,2.5,3.0,3.5]
34+
x2=[4.,5.,1.,1.5,2.,2.5,3.0,3.5]
35+
y2=[6.,4.,1.,1.5,2.,2.5,3.0,3.5]
36+
37+
!------ slice problem
38+
s0 = (im-1)*Np/Ni+1
39+
s1 = im*Np/Ni
40+
print '(A,I3,A,I3,A,I3)','Image',im,' solved over indices ',s0,':',s1
41+
!------- solve problem
42+
call cohensutherland(xmin,ymax,xmax,ymin, &
43+
x1(s0:s1), y1(s0:s1), x2(s0:s1), y2(s0:s1))
44+
45+
length(s0:s1)[1] = hypot(x2(s0:s1) - x1(s0:s1), y2(s0:s1) - y1(s0:s1))
46+
!-------- finish up
47+
sync all
48+
49+
if (im==1) then
50+
call assert_isclose(length, truelength, equal_nan=.true.)
51+
print *, 'OK coarray_lineclip'
52+
endif
53+
54+
55+
end subroutine coarray_lineclip
56+
57+
end program

DemoLineclip.f90

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ program test
66

77
implicit none
88

9-
real(wp) :: L(8)[*]
10-
11-
if(this_image()==1) then
12-
call test_lineclip()
13-
14-
call test_array_lineclip()
15-
endif
16-
17-
call coarray_lineclip(L)
18-
! if(this_image()==1) print *,L
9+
call test_lineclip()
10+
call test_array_lineclip()
1911

2012
contains
2113

@@ -80,47 +72,5 @@ subroutine test_lineclip()
8072

8173
end subroutine test_lineclip
8274

83-
!----------------------------
84-
85-
subroutine coarray_lineclip(length)
86-
87-
integer, parameter :: Np=8
88-
real(wp), dimension(Np) :: x1,x2,y1,y2
89-
real(wp),parameter :: xmin=1., ymax=5.,xmax=4., ymin=3.
90-
real(wp) :: truelength(Np) =[2.40370083, 3.,0.,0.,0.,0.,2.,2.5]
91-
real(wp) :: nan
92-
integer :: Ni, im, s0,s1
93-
real(wp),intent(out) :: length(Np)[*]
94-
95-
Ni = num_images()
96-
im=this_image()
97-
98-
nan = ieee_value(1.,ieee_quiet_nan)
99-
truelength(3:6) = nan
100-
101-
x1=[0.,0.,0.,0.,0.,0.,0.,0.]
102-
y1=[0.,4.,1.,1.5,2.,2.5,3.0,3.5]
103-
x2=[4.,5.,1.,1.5,2.,2.5,3.0,3.5]
104-
y2=[6.,4.,1.,1.5,2.,2.5,3.0,3.5]
105-
106-
!------ slice problem
107-
s0 = (im-1)*Np/Ni+1
108-
s1 = im*Np/Ni
109-
print '(A,I3,A,I3,A,I3)','Image',im,' solved over indices ',s0,':',s1
110-
!------- solve problem
111-
call cohensutherland(xmin,ymax,xmax,ymin, &
112-
x1(s0:s1), y1(s0:s1), x2(s0:s1), y2(s0:s1))
113-
114-
length(s0:s1)[1] = hypot(x2(s0:s1) - x1(s0:s1), y2(s0:s1) - y1(s0:s1))
115-
!-------- finish up
116-
sync all
117-
118-
if (im==1) then
119-
call assert_isclose(length, truelength, equal_nan=.true.)
120-
print *, 'OK coarray_lineclip'
121-
endif
122-
123-
124-
end subroutine coarray_lineclip
12575

12676
end program

README.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ If you want to use the Fortran Cohen-Sutherland line clipping modules directly (
3030
cd bin
3131
cmake ..
3232
make
33-
34-
If you don't have a modern Fortran compiler with coarray support, do::
3533

36-
cd bin
37-
TRAVIS=1 cmake ..
38-
make
39-
4034

4135
Usage
4236
=====
@@ -47,7 +41,7 @@ Python
4741

4842
.. code:: python
4943
50-
import morecvutils.lineclipping as lc
44+
import pylineclip.lineclipping as lc
5145
5246
x3,y3,x4,y4 = lc.cohensutherland((xmin, ymax, xmax, ymin, x1, y1, x2, y2)
5347

setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@
1212
author='Michael Hirsch, Ph.D.',
1313
url='https://github.com/scivision/lineclipping-python-fortran',
1414
classifiers=[
15-
'Intended Audience :: Science/Research',
1615
'Development Status :: 4 - Beta',
16+
'Environment :: Console',
17+
'Intended Audience :: Science/Research',
1718
'License :: OSI Approved :: MIT License',
19+
'Operating System :: OS Independent',
20+
'Programming Language :: Python :: 2.7',
21+
'Programming Language :: Python :: 3.4',
22+
'Programming Language :: Python :: 3.5',
23+
'Programming Language :: Python :: 3.6',
24+
'Programming Language :: Python :: 3.7',
1825
'Topic :: Scientific/Engineering :: Visualization',
19-
'Programming Language :: Python :: 3',
2026
],
2127
install_requires=install_requires,
2228
tests_require=tests_require,
2329
extras_require={'tests':tests_require},
2430
python_requires='>=2.7',
31+
scripts=['DemoLineclip.py'],
32+
include_package_data=True,
2533
)
2634

0 commit comments

Comments
 (0)