Implement thread creation for WindowsBRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: Sean, Daniel RossbergTags: C, C++, Windows, mutex, SMP, threading

BRL-CAD implements support for running in parallel on computers with multiple CPUs or cores. However, there are lots of ways to run in parallel. BRL-CAD runs on Windows, but presently only in a single-threaded mode. To make it work in parallel, we need to define how threads are created.

This task involves implementing the necessary logic to create a new thread in bu_parallel(). This requires a very minor source code modification to just one file, but make sure it works with a simple test program. Make your program call bu_parallel(), see include/bu.h for API docs.

References:

Code:

  • src/libbu/parallel.c
Uploaded Work
File name/URLFile sizeDate submitted
parallel.c28.6 KBDecember 04 2012 15:25 UTC
Win32threads.patch2.0 KBDecember 04 2012 17:21 UTC
BRL-CADThreads.patch1.4 KBDecember 05 2012 14:31 UTC
ThirdPatch.patch1.3 KBDecember 05 2012 15:01 UTC
Thread.patch1.1 KBDecember 05 2012 18:33 UTC
WThread.patch1.7 KBDecember 06 2012 10:59 UTC
Thread2.patch1.6 KBDecember 06 2012 14:44 UTC
Thread3.patch1.5 KBDecember 06 2012 16:47 UTC
Comments
Adrián Arroyo Calleon December 4 2012 14:52 UTCTask Claimed

I would like to work on this task.

Harmanpreet Singh on December 4 2012 14:54 UTCTask Assigned

This task has been assigned to Adrián Arroyo Calle. You have 48 hours to complete this task, good luck!

Adrián Arroyo Calleon December 4 2012 15:26 UTCSubmit new file

I submited a new file. Check the file and tell me the errors. Thanks in advance.

Daniel Rossberg on December 4 2012 15:47 UTCPlease provide a patch file

and take our coding conventions into account (the HACKING file).

Adrián Arroyo Calleon December 4 2012 17:22 UTCPatch file

I read the HACKING file and I change some of this { }. I create a patch file and the program will work

Adrián Arroyo Calleon December 4 2012 18:35 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 5 2012 03:03 UTCfew issues

Adrián, that's looking good but I noticed a few problems.  The biggest is that you need to wait for all threads to complete before allowing the bu_parallel() function to return.  Something similar to pthread_join().  See the other sections for examples.


Another problem is the formatting is a terrible mess!  :)  Your indentation doesn't follow our coding style (please read our HACKING file).  Indentation needs to be pristine and matching the rest of the file.  Indents should be 4 char, 1 tab, 1 tab + 4 char, 2 tab, 2 tab + 4 char, etc.  There shouldn't be a slew of empty blank lines, there shouldn't be XXX comments for new code.  Formatting isn't just nice to have -- it's just as important as the code itself so please work to get it right.


Finally, what are the pDataArray values supposed to mean?  I see the first is the cpu number, but why is the second incremented by 100?


 

Sean on December 5 2012 03:03 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Adrián Arroyo Calleon December 5 2012 14:32 UTCReady for review

The work on this task is ready to be reviewed.

Adrián Arroyo Calleon December 5 2012 14:36 UTCNew patch

I submited a new patch including the pthread_join() equivalent in WinAPI. I also change some of the coding style and the pDataArray is only a number for create the thread. So, I'm ready for review

Sean on December 5 2012 15:14 UTCinvalid patch file

The ThirdPatch.patch file is not a valid patch file.  Also, the changes still do not conform to our coding style.  The indentation is wrong and you still have a slew of superfluous blank lines being added.  That's obvious without even applying the file just by reading the patch file.


Since this is apparently something you're having difficulty seeing, perhaps you may want to try using automatic formatting.  This extension to visual studio might help you:


http://code.google.com/p/extabsettings/


It should also go without saying, but given the other issues ... have you made sure that your patch compiles cleanly?


Last, you didn't answer my question about pDataArray.  I know it's a number for creating the thread, what does the number mean?  What is it used for?  Why is it 100 greater than the CPU id?  Magic numbers must be documented with a comment, you need to say what that '100' is for or what that field in the array is for in more detail.

Adrián Arroyo Calleon December 5 2012 18:43 UTCNew patch file

I submited a new patch file, I check it ThirdPatch.patch and now I know the character limit in filename. I change the tabs (thanks for the add-in) and I delete blank lines. I tested the patch in small program like the task says: but make sure it works with a simple test program. My small program calls a function declared like parallel_interface(), it works on Win32 and Win64. The pDataArray was an error, because the Microsoft code has arguments. I removed it.

Sean on December 6 2012 06:48 UTCstill not a valid patch file

The format of your file is still not a valid patch file.  How are you making that file??  If you have a subversion client, it will generate the patch file for you.  Also, the indentation is still wrong -- your file has tabs on the first indent, which should be four spaces.

Sean on December 6 2012 06:48 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 6 2012 06:48 UTCDeadline extended

The deadline of the task has been extended with 0 days and 12 hours.

Adrián Arroyo Calleon December 6 2012 11:06 UTCReady for review

The work on this task is ready to be reviewed.

Adrián Arroyo Calleon December 6 2012 11:08 UTCNew patch file

The tool for creating patch on Windows needs some arguments, but now the patch is valid. I re-write the spaces and I think that now are good. Thanks for more time (in Spain today is a non-working day).

Daniel Rossberg on December 6 2012 11:49 UTCSome shortfalls


  • The include windows.h shouldn't be neccessary because it will be done in bio.h, and the way you did it could cause problems with cygwin too.

  • Why did you changed one of the "Create the threads" comments (and only this one)?

  • The 1st level content of your 1st for-loop needs an additional indent.

  • The indent of the "Wait for other threads" comment doesn't look pretty too.

Daniel Rossberg on December 6 2012 11:49 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Adrián Arroyo Calleon December 6 2012 14:45 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 6 2012 16:29 UTCThere are still some shortfalls


  • 8 spaces (2 indents)  = 1 tab

  • Don't write your name in the code.  If we all would do this it would be a mess.  The version control system (here Subversion) takes care of the changes and who did them.  And for the acknoeledgement there is an AUTHORS file too.

Daniel Rossberg on December 6 2012 16:29 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Adrián Arroyo Calleon December 6 2012 16:47 UTCReady for review

The work on this task is ready to be reviewed.

Melange on December 7 2012 04:59 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on December 7 2012 05:48 UTCnow that's...

Now that's looking like a proper patch!  I haven't tested whether it actually compiles, but the patch applied cleanly.  There were STILL three problems with the patch including an outright syntax error, so it certainly doesn't compile in its latest final form.  Other problems were trailing whitespace, ifdef/endif indenation was wrong, and you were missing a semicolon(!).


Still, you've put reasonable efffort in.  I have credited your contribution in our authorship documentation and you'll be included in a future release announcement.  We'll be creating another task to properly test this change that you might want to keep an eye out for.

Sean on December 7 2012 05:49 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 17 2012 23:50 UTCfollow-on task

A follow-on task has been posted:


http://www.google-melange.com/gci/task/view/google/gci2012/8086204


 

Sean on January 14 2013 15:24 UTCthank you

As GCI comes to a close, we wanted to take the time to say THANK YOU for all your efforts.  This comment interface closes after GCI is over, so you're encouraged to join our mailing list where we'll be announcing contributions from GCI participants like yourelf over the upcoming months: 


https://lists.sourceforge.net/lists/listinfo/brlcad-news


If you've provided your full name, we'll be sure to credit you in our authorship documentation and you'll see your name in a future announcement.  If you contact us at devs@brlcad.org or via IRC, we'll even let you know when your work is integrated and follow up with updates.  You're welcome and encouraged to contact us any time, especially if you have a question about how to continue participating in Open Source after GCI is over, but even if just to keep in touch.  Note that ongoing participation in Open Source is one of the most impressive skills to have on your resumé.  Take care, be well, and thank you again!


This feature is going to make a particularly huge impact with our community when it headlines a release. ;)