I need to implement a link list data structure for my molecular dynamics code in fortran 2003/2008 I am using the newest fortran compilers (Intel).
How do I come about implement the linked list in the best way possible I would prefer a lock-free no wait implementation if possible in Fortran.
Thank you.
It is easiest if you create a user defined type with your data items and the pointer to the next item. This is assuming a singly-linked list. e.g.,
type MyList_type
integer :: FirstItem
real :: SecondItem
etc
type (MyList_type), pointer :: next_ptr => null ()
end type MyList_type
Then create the first member with "allocate". Thereafter you write code to traverse the list, using next_ptr to step through the list. Use the "associated" intrinsic function to test whether next_ptr is defined yet, or instead you have reached the end of the list.
If you are writing an ordinary sequential Fortran program then lock-free/no-wait is not an issue. If you are writing a multi-threaded / parallel program, then consistent access to the variables is an issue.
Here are some more examples: http://fortranwiki.org/fortran/show/Linked+list. Even better, linked lists in Fortran are clearly explained in the book "Fortran 90/95 Explained" by Metcalf and Reid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With