Skip to content

Commit c008b2a

Browse files
modify to be able to compile with OpenCoarrays
1 parent f95f965 commit c008b2a

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

example/lu_decomp/main.f90

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ program main
2626
close(f_unit)
2727
end if
2828
open(file=timing_file, newunit = f_unit, status="old", position = "append")
29-
write(f_unit, '(I0, ",", I0, ",", I0, ",", G0)') matrix_size, size(tasks%vertices), num_images(), real(finish-start)/real(count_rate)
29+
write(f_unit, '(I0, ",", I0, ",", I0, ",", G0)') &
30+
matrix_size, size(tasks%vertices), num_images(), real(finish-start)/real(count_rate)
3031
end if
3132
end program

src/payload_m.f90

+27-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module payload_m
33
private
44
public :: payload_t, empty_payload
55

6+
integer, parameter :: MAX_PAYLOAD_SIZE = 20002
7+
68
type :: payload_t
79
!! A raw buffer to facilitate data transfer between images
810
!!
@@ -11,7 +13,8 @@ module payload_m
1113
!! * produce a string representation of the data, and then parse that string to recover the original data
1214
!! * use the `transfer` function to copy the raw bytes of the data
1315
private
14-
integer, public, allocatable :: payload_(:)
16+
integer, public :: payload_(MAX_PAYLOAD_SIZE)
17+
integer :: payload_size = 0
1518
contains
1619
private
1720
procedure, public :: raw_payload
@@ -29,42 +32,58 @@ pure function from_raw(payload) result(new_payload)
2932
integer, intent(in) :: payload(:)
3033
type(payload_t) :: new_payload
3134

32-
allocate(new_payload%payload_, source = payload)
35+
integer :: incoming_payload_size
36+
37+
incoming_payload_size = size(payload)
38+
if (incoming_payload_size > MAX_PAYLOAD_SIZE) then
39+
new_payload%payload_size = MAX_PAYLOAD_SIZE
40+
new_payload%payload_ = payload(1:MAX_PAYLOAD_SIZE)
41+
else
42+
new_payload%payload_size = incoming_payload_size
43+
new_payload%payload_(1:incoming_payload_size) = payload
44+
end if
3345
end function
3446

3547
pure function from_string(payload) result(new_payload)
3648
implicit none
3749
character(len=*), intent(in) :: payload
3850
type(payload_t) :: new_payload
3951

40-
new_payload = payload_t([len(payload), transfer(payload, new_payload%payload_)])
52+
new_payload%payload_(1) = len(payload)
53+
associate(string_as_integers => transfer(payload, new_payload%payload_))
54+
if (size(string_as_integers) > MAX_PAYLOAD_SIZE-1) then
55+
new_payload%payload_size = MAX_PAYLOAD_SIZE
56+
new_payload%payload_(2:MAX_PAYLOAD_SIZE) = string_as_integers(1:MAX_PAYLOAD_SIZE-1)
57+
else
58+
new_payload%payload_size = size(string_as_integers) + 1
59+
new_payload%payload_(2:new_payload%payload_size) = string_as_integers
60+
end if
61+
end associate
4162
end function
4263

4364
pure function empty_payload()
4465
implicit none
4566
type(payload_t) :: empty_payload
46-
47-
allocate(empty_payload%payload_(0))
4867
end function
4968

5069
pure function raw_payload(self)
5170
implicit none
5271
class(payload_t), intent(in) :: self
5372
integer, allocatable :: raw_payload(:)
5473

55-
raw_payload = self%payload_
74+
raw_payload = self%payload_(1:self%payload_size)
5675
end function
5776

5877
pure function string_payload(self)
5978
implicit none
6079
class(payload_t), intent(in) :: self
6180
character(len=:), allocatable :: string_payload
6281

63-
if (size(self%payload_) > 0) then
82+
if (self%payload_size > 0) then
6483
allocate(character(len=self%payload_(1)) :: string_payload)
6584
if (self%payload_(1) > 0) &
6685
string_payload = transfer( &
67-
self%payload_(2:), string_payload)
86+
self%payload_(2:self%payload_size), string_payload)
6887
else
6988
allocate(character(len=0) :: string_payload)
7089
end if

src/vertex_m.f90

+13
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ module vertex_m
1515
integer, allocatable :: edges(:)
1616
class(task_t), allocatable :: task
1717
end type
18+
19+
interface vertex_t
20+
module procedure construct
21+
end interface
22+
contains
23+
function construct(edges, task) result(vertex)
24+
integer, intent(in) :: edges(:)
25+
class(task_t), intent(in) :: task
26+
type(vertex_t) :: vertex
27+
28+
vertex%edges = edges
29+
vertex%task = task
30+
end function
1831
end module vertex_m

0 commit comments

Comments
 (0)