Hi Yu,
Since you didn’t provide a reproducing example code, it’s a bit difficult to say what’s wrong here. It appears you may be trying to build the list from the host, which would be problematic given you’d be allocating host addresses.
If this is being done on the device, you’d have a separate problem in that each “Pointer_Row_Start” element will most likely have it’s own value and column, it’s not getting the values from “tail”, just the next pointer is updated. Hence, I’d probably make this an array of a type that contains the pointer to the node.
Another item I not sure about is that you name the array “Pointer_Row_Start” which implies to me that each contains the starting head node of a list (row). But how you’ve coded here it seem more a quick way to index into the list without having to traverse it.
Again, we don’t recommend using linked list. They are poor choice for use in parallel programming. It might be better if each thread managed it’s own row, but it’s likely that using multidimensional arrays of types would be better. Though, you probably have your reasons as to why to use linked lists, so I wont question.
Below are two example codes that I just wrote, the first if you want Pointer_Row_Start to be a quick index into the list, and the second if Pointer_Row_Start has it’s own list. I can’t say if this is the best or most efficient way to write these (given I don’t use linked lists on GPUs), but hopefully will help you work through the issue you’re having with your code.
Example 1
% cat linked.cuf
MODULE ListModule
IMPLICIT NONE
TYPE node
Integer :: Column
DOUBLE PRECISION :: value;
TYPE(node), POINTER :: next;
END TYPE node
TYPE node_list
TYPE(node), POINTER :: node;
end type node_list
type(node_list), allocatable, dimension(:), device :: Pointer_Row_Start
end module ListModule
module test
use listmodule
CONTAINS
ATTRIBUTES(GLOBAL) SUBROUTINE createList(Number)
IMPLICIT NONE
integer, value :: Number
type( node ), pointer, device :: head, tail, next
integer :: i
do i=1,Number
if (.not.associated(head)) then
allocate(head)
tail=>head
nullify(tail%next)
tail%value=i
tail%column=i
Pointer_Row_Start(i)%node => tail
else
allocate(next)
tail%next => next
tail=>tail%next
nullify(next)
nullify(tail%next)
tail%value=i
tail%column=i
Pointer_Row_Start(i)%node => tail
endif
end do
End subroutine createList
ATTRIBUTES(GLOBAL) SUBROUTINE printList(start)
integer, value :: start
type( node ), pointer :: curr
print *, "=== START at ", start, "==========="
curr => Pointer_Row_Start(start)%node
do while(associated(curr))
print *, curr%value, curr%column
curr=>curr%next
end do
end subroutine printList
END MODULE test
PROGRAM LinkedList
USE listmodule
use test
USE CUDAFOR
integer :: Number
Number=32
allocate(Pointer_Row_Start(Number))
CALL createList<<<1,1>>>(Number)
CALL printList<<<1,1>>>(1)
CALL printList<<<1,1>>>(30)
N=cudaDeviceSynchronize()
END PROGRAM LinkedList
% nvfortran linked.cuf; a.out
=== START at 1 ===========
1.000000000000000 1
2.000000000000000 2
3.000000000000000 3
4.000000000000000 4
5.000000000000000 5
6.000000000000000 6
7.000000000000000 7
8.000000000000000 8
9.000000000000000 9
10.00000000000000 10
11.00000000000000 11
12.00000000000000 12
13.00000000000000 13
14.00000000000000 14
15.00000000000000 15
16.00000000000000 16
17.00000000000000 17
18.00000000000000 18
19.00000000000000 19
20.00000000000000 20
21.00000000000000 21
22.00000000000000 22
23.00000000000000 23
24.00000000000000 24
25.00000000000000 25
26.00000000000000 26
27.00000000000000 27
28.00000000000000 28
29.00000000000000 29
30.00000000000000 30
31.00000000000000 31
32.00000000000000 32
=== START at 30 ===========
30.00000000000000 30
31.00000000000000 31
32.00000000000000 32
Example 2:
% cat linkedRow.cuf
MODULE ListModule
IMPLICIT NONE
TYPE node
Integer :: Column
DOUBLE PRECISION :: value;
TYPE(node), POINTER :: next;
END TYPE node
TYPE node_list
TYPE(node), POINTER :: head;
end type node_list
type(node_list), allocatable, dimension(:), device :: Pointer_Row_Start
end module ListModule
module test
use listmodule
CONTAINS
ATTRIBUTES(GLOBAL) SUBROUTINE createRow(rowid,numnodes)
IMPLICIT NONE
integer, value :: rowid,numnodes
type( node ), pointer, device :: head,curr, next
integer :: i
nullify(head)
Pointer_Row_Start(rowid)%head=>head
do i=1,numnodes
if (.not.associated(head)) then
allocate(head)
Pointer_Row_Start(rowid)%head=>head
curr=>head
curr%value=rowid
curr%column=i
nullify(curr%next)
else
allocate(next)
curr%next=>next
curr=>next
nullify(curr%next)
curr%value=rowid
curr%column=i
endif
end do
End subroutine createRow
ATTRIBUTES(GLOBAL) SUBROUTINE printRow(rowid)
integer, value :: rowid
type( node ), pointer :: curr
print *, "=== Row ", rowid , "==========="
curr => Pointer_Row_Start(rowid)%head
do while(associated(curr))
print *, curr%value, curr%column
curr=>curr%next
end do
end subroutine printRow
END MODULE test
PROGRAM LinkedList
USE listmodule
use test
USE CUDAFOR
integer :: numRows, rowid
numRows=32
allocate(Pointer_Row_Start(numRows))
do rowid=1,numRows
CALL createRow<<<1,1>>>(rowid,rowid-1)
enddo
do rowid=1,numRows
CALL printRow<<<1,1>>>(rowid)
enddo
N=cudaDeviceSynchronize()
END PROGRAM LinkedList
dev-sky5:/local/home/mcolgrove% nvfortran linkedRow.cuf ; a.out
=== Row 1 ===========
=== Row 2 ===========
2.000000000000000 1
=== Row 3 ===========
3.000000000000000 1
3.000000000000000 2
=== Row 4 ===========
4.000000000000000 1
4.000000000000000 2
4.000000000000000 3
=== Row 5 ===========
5.000000000000000 1
5.000000000000000 2
5.000000000000000 3
5.000000000000000 4
=== Row 6 ===========
6.000000000000000 1
6.000000000000000 2
6.000000000000000 3
6.000000000000000 4
6.000000000000000 5
=== Row 7 ===========
7.000000000000000 1
7.000000000000000 2
7.000000000000000 3
7.000000000000000 4
7.000000000000000 5
7.000000000000000 6
=== Row 8 ===========
8.000000000000000 1
8.000000000000000 2
8.000000000000000 3
8.000000000000000 4
8.000000000000000 5
8.000000000000000 6
8.000000000000000 7
=== Row 9 ===========
9.000000000000000 1
9.000000000000000 2
9.000000000000000 3
9.000000000000000 4
9.000000000000000 5
9.000000000000000 6
9.000000000000000 7
9.000000000000000 8
=== Row 10 ===========
10.00000000000000 1
10.00000000000000 2
10.00000000000000 3
10.00000000000000 4
10.00000000000000 5
10.00000000000000 6
10.00000000000000 7
10.00000000000000 8
10.00000000000000 9
=== Row 11 ===========
11.00000000000000 1
11.00000000000000 2
11.00000000000000 3
11.00000000000000 4
11.00000000000000 5
11.00000000000000 6
11.00000000000000 7
11.00000000000000 8
11.00000000000000 9
11.00000000000000 10
=== Row 12 ===========
12.00000000000000 1
12.00000000000000 2
12.00000000000000 3
12.00000000000000 4
12.00000000000000 5
12.00000000000000 6
12.00000000000000 7
12.00000000000000 8
12.00000000000000 9
12.00000000000000 10
12.00000000000000 11
=== Row 13 ===========
13.00000000000000 1
13.00000000000000 2
13.00000000000000 3
13.00000000000000 4
13.00000000000000 5
13.00000000000000 6
13.00000000000000 7
13.00000000000000 8
13.00000000000000 9
13.00000000000000 10
13.00000000000000 11
13.00000000000000 12
=== Row 14 ===========
14.00000000000000 1
14.00000000000000 2
14.00000000000000 3
14.00000000000000 4
14.00000000000000 5
14.00000000000000 6
14.00000000000000 7
14.00000000000000 8
14.00000000000000 9
14.00000000000000 10
14.00000000000000 11
14.00000000000000 12
14.00000000000000 13
=== Row 15 ===========
15.00000000000000 1
15.00000000000000 2
15.00000000000000 3
15.00000000000000 4
15.00000000000000 5
15.00000000000000 6
15.00000000000000 7
15.00000000000000 8
15.00000000000000 9
15.00000000000000 10
15.00000000000000 11
15.00000000000000 12
15.00000000000000 13
15.00000000000000 14
=== Row 16 ===========
16.00000000000000 1
16.00000000000000 2
16.00000000000000 3
16.00000000000000 4
16.00000000000000 5
16.00000000000000 6
16.00000000000000 7
16.00000000000000 8
16.00000000000000 9
16.00000000000000 10
16.00000000000000 11
16.00000000000000 12
16.00000000000000 13
16.00000000000000 14
16.00000000000000 15
=== Row 17 ===========
17.00000000000000 1
17.00000000000000 2
17.00000000000000 3
17.00000000000000 4
17.00000000000000 5
17.00000000000000 6
17.00000000000000 7
17.00000000000000 8
17.00000000000000 9
17.00000000000000 10
17.00000000000000 11
17.00000000000000 12
17.00000000000000 13
17.00000000000000 14
17.00000000000000 15
17.00000000000000 16
=== Row 18 ===========
18.00000000000000 1
18.00000000000000 2
18.00000000000000 3
18.00000000000000 4
18.00000000000000 5
18.00000000000000 6
18.00000000000000 7
18.00000000000000 8
18.00000000000000 9
18.00000000000000 10
18.00000000000000 11
18.00000000000000 12
18.00000000000000 13
18.00000000000000 14
18.00000000000000 15
18.00000000000000 16
18.00000000000000 17
=== Row 19 ===========
19.00000000000000 1
19.00000000000000 2
19.00000000000000 3
19.00000000000000 4
19.00000000000000 5
19.00000000000000 6
19.00000000000000 7
19.00000000000000 8
19.00000000000000 9
19.00000000000000 10
19.00000000000000 11
19.00000000000000 12
19.00000000000000 13
19.00000000000000 14
19.00000000000000 15
19.00000000000000 16
19.00000000000000 17
19.00000000000000 18
=== Row 20 ===========
20.00000000000000 1
20.00000000000000 2
20.00000000000000 3
20.00000000000000 4
20.00000000000000 5
20.00000000000000 6
20.00000000000000 7
20.00000000000000 8
20.00000000000000 9
20.00000000000000 10
20.00000000000000 11
20.00000000000000 12
20.00000000000000 13
20.00000000000000 14
20.00000000000000 15
20.00000000000000 16
20.00000000000000 17
20.00000000000000 18
20.00000000000000 19
=== Row 21 ===========
21.00000000000000 1
21.00000000000000 2
21.00000000000000 3
21.00000000000000 4
21.00000000000000 5
21.00000000000000 6
21.00000000000000 7
21.00000000000000 8
21.00000000000000 9
21.00000000000000 10
21.00000000000000 11
21.00000000000000 12
21.00000000000000 13
21.00000000000000 14
21.00000000000000 15
21.00000000000000 16
21.00000000000000 17
21.00000000000000 18
21.00000000000000 19
21.00000000000000 20
=== Row 22 ===========
22.00000000000000 1
22.00000000000000 2
22.00000000000000 3
22.00000000000000 4
22.00000000000000 5
22.00000000000000 6
22.00000000000000 7
22.00000000000000 8
22.00000000000000 9
22.00000000000000 10
22.00000000000000 11
22.00000000000000 12
22.00000000000000 13
22.00000000000000 14
22.00000000000000 15
22.00000000000000 16
22.00000000000000 17
22.00000000000000 18
22.00000000000000 19
22.00000000000000 20
22.00000000000000 21
=== Row 23 ===========
23.00000000000000 1
23.00000000000000 2
23.00000000000000 3
23.00000000000000 4
23.00000000000000 5
23.00000000000000 6
23.00000000000000 7
23.00000000000000 8
23.00000000000000 9
23.00000000000000 10
23.00000000000000 11
23.00000000000000 12
23.00000000000000 13
23.00000000000000 14
23.00000000000000 15
23.00000000000000 16
23.00000000000000 17
23.00000000000000 18
23.00000000000000 19
23.00000000000000 20
23.00000000000000 21
23.00000000000000 22
=== Row 24 ===========
24.00000000000000 1
24.00000000000000 2
24.00000000000000 3
24.00000000000000 4
24.00000000000000 5
24.00000000000000 6
24.00000000000000 7
24.00000000000000 8
24.00000000000000 9
24.00000000000000 10
24.00000000000000 11
24.00000000000000 12
24.00000000000000 13
24.00000000000000 14
24.00000000000000 15
24.00000000000000 16
24.00000000000000 17
24.00000000000000 18
24.00000000000000 19
24.00000000000000 20
24.00000000000000 21
24.00000000000000 22
24.00000000000000 23
=== Row 25 ===========
25.00000000000000 1
25.00000000000000 2
25.00000000000000 3
25.00000000000000 4
25.00000000000000 5
25.00000000000000 6
25.00000000000000 7
25.00000000000000 8
25.00000000000000 9
25.00000000000000 10
25.00000000000000 11
25.00000000000000 12
25.00000000000000 13
25.00000000000000 14
25.00000000000000 15
25.00000000000000 16
25.00000000000000 17
25.00000000000000 18
25.00000000000000 19
25.00000000000000 20
25.00000000000000 21
25.00000000000000 22
25.00000000000000 23
25.00000000000000 24
=== Row 26 ===========
26.00000000000000 1
26.00000000000000 2
26.00000000000000 3
26.00000000000000 4
26.00000000000000 5
26.00000000000000 6
26.00000000000000 7
26.00000000000000 8
26.00000000000000 9
26.00000000000000 10
26.00000000000000 11
26.00000000000000 12
26.00000000000000 13
26.00000000000000 14
26.00000000000000 15
26.00000000000000 16
26.00000000000000 17
26.00000000000000 18
26.00000000000000 19
26.00000000000000 20
26.00000000000000 21
26.00000000000000 22
26.00000000000000 23
26.00000000000000 24
26.00000000000000 25
=== Row 27 ===========
27.00000000000000 1
27.00000000000000 2
27.00000000000000 3
27.00000000000000 4
27.00000000000000 5
27.00000000000000 6
27.00000000000000 7
27.00000000000000 8
27.00000000000000 9
27.00000000000000 10
27.00000000000000 11
27.00000000000000 12
27.00000000000000 13
27.00000000000000 14
27.00000000000000 15
27.00000000000000 16
27.00000000000000 17
27.00000000000000 18
27.00000000000000 19
27.00000000000000 20
27.00000000000000 21
27.00000000000000 22
27.00000000000000 23
27.00000000000000 24
27.00000000000000 25
27.00000000000000 26
=== Row 28 ===========
28.00000000000000 1
28.00000000000000 2
28.00000000000000 3
28.00000000000000 4
28.00000000000000 5
28.00000000000000 6
28.00000000000000 7
28.00000000000000 8
28.00000000000000 9
28.00000000000000 10
28.00000000000000 11
28.00000000000000 12
28.00000000000000 13
28.00000000000000 14
28.00000000000000 15
28.00000000000000 16
28.00000000000000 17
28.00000000000000 18
28.00000000000000 19
28.00000000000000 20
28.00000000000000 21
28.00000000000000 22
28.00000000000000 23
28.00000000000000 24
28.00000000000000 25
28.00000000000000 26
28.00000000000000 27
=== Row 29 ===========
29.00000000000000 1
29.00000000000000 2
29.00000000000000 3
29.00000000000000 4
29.00000000000000 5
29.00000000000000 6
29.00000000000000 7
29.00000000000000 8
29.00000000000000 9
29.00000000000000 10
29.00000000000000 11
29.00000000000000 12
29.00000000000000 13
29.00000000000000 14
29.00000000000000 15
29.00000000000000 16
29.00000000000000 17
29.00000000000000 18
29.00000000000000 19
29.00000000000000 20
29.00000000000000 21
29.00000000000000 22
29.00000000000000 23
29.00000000000000 24
29.00000000000000 25
29.00000000000000 26
29.00000000000000 27
29.00000000000000 28
=== Row 30 ===========
30.00000000000000 1
30.00000000000000 2
30.00000000000000 3
30.00000000000000 4
30.00000000000000 5
30.00000000000000 6
30.00000000000000 7
30.00000000000000 8
30.00000000000000 9
30.00000000000000 10
30.00000000000000 11
30.00000000000000 12
30.00000000000000 13
30.00000000000000 14
30.00000000000000 15
30.00000000000000 16
30.00000000000000 17
30.00000000000000 18
30.00000000000000 19
30.00000000000000 20
30.00000000000000 21
30.00000000000000 22
30.00000000000000 23
30.00000000000000 24
30.00000000000000 25
30.00000000000000 26
30.00000000000000 27
30.00000000000000 28
30.00000000000000 29
=== Row 31 ===========
31.00000000000000 1
31.00000000000000 2
31.00000000000000 3
31.00000000000000 4
31.00000000000000 5
31.00000000000000 6
31.00000000000000 7
31.00000000000000 8
31.00000000000000 9
31.00000000000000 10
31.00000000000000 11
31.00000000000000 12
31.00000000000000 13
31.00000000000000 14
31.00000000000000 15
31.00000000000000 16
31.00000000000000 17
31.00000000000000 18
31.00000000000000 19
31.00000000000000 20
31.00000000000000 21
31.00000000000000 22
31.00000000000000 23
31.00000000000000 24
31.00000000000000 25
31.00000000000000 26
31.00000000000000 27
31.00000000000000 28
31.00000000000000 29
31.00000000000000 30
=== Row 32 ===========
32.00000000000000 1
32.00000000000000 2
32.00000000000000 3
32.00000000000000 4
32.00000000000000 5
32.00000000000000 6
32.00000000000000 7
32.00000000000000 8
32.00000000000000 9
32.00000000000000 10
32.00000000000000 11
32.00000000000000 12
32.00000000000000 13
32.00000000000000 14
32.00000000000000 15
32.00000000000000 16
32.00000000000000 17
32.00000000000000 18
32.00000000000000 19
32.00000000000000 20
32.00000000000000 21
32.00000000000000 22
32.00000000000000 23
32.00000000000000 24
32.00000000000000 25
32.00000000000000 26
32.00000000000000 27
32.00000000000000 28
32.00000000000000 29
32.00000000000000 30
32.00000000000000 31
-Mat