Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Parallel Implementation of DFS for undirected graph

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Thanked 0 Times in 0 Posts

    Default Parallel Implementation of DFS for undirected graph

    I have been trying to implement a parallel Depth First Search in Java for undirected graph. The approach I decided to implement uses one global stack which is shared by all the threads and n local stacks where n is the number of threads. Each thread stores the nodes of its sub-tree in its local stack. Initially the global stack contains the root of the tree and only one thread gets access to it while the other threads are waiting to be woken up by the working thread. The working thread retrieves and processes the root from the global stack, adds one successor to its local stack then pushes the rest of the successors, if they exist, to the global stack to be processed by other threads and wakes up all the waiting threads. All the other threads follow the same approach (i.e. when threads get a node from the global stack they push one successor to their local stack and the rest to the global stack then start accessing their local stack until it becomes empty).

    The problem is it doesn't speed up. Will give me any suggestions on how to improve it? Thank you in advance.

    (I attached my code)

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: Parallel Implementation of DFS for undirected graph

    Please post your code directly to the forums - ideally with extraneous code omitted and posted as an SSCCE - many here (including myself) are unwilling to download a zip compressed file. It may also be helpful to post how many threads you are using and perhaps how many processors your testing computer has.

Similar Threads

  1. Euler Paths with dfs algorithm problem
    By claudio.r in forum Algorithms & Recursion
    Replies: 18
    Last Post: March 22nd, 2012, 04:39 PM
  2. Trouble Creating a DFS Maze
    By I_need_a_new_name in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 19th, 2012, 05:57 PM
  3. Replies: 1
    Last Post: February 11th, 2012, 07:38 AM
  4. DFS in Graphs
    By antislayer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2011, 09:01 AM
  5. Java Bar graph takes user input to create graph?
    By kenjiro310 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:37 AM