Brooks ([info]brooksmoses) wrote,
@ 2008-04-28 16:39:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
So, this is how it goes, eh?
I just wrote my very first multithreaded program using pthreads. A very simple "Hello World" that creates a short array of thread numbers, and then creates a thread for each element in that array; each thread then loads its respective number from the array and prints out, "Hello, I am thread %d!"

Shortly thereafter, I debugged my first race condition in a multithreaded program.

I suppose this is the way of things, then?


(Post a new comment)


[info]technolope
2008-04-29 12:07 am UTC (link)
Are you planning to do complicated stuff with threads? Because OpenMP is a CFD programmer's best friend. (IMHO)

Of course, it doesn't help that classic old libraries like FishPak aren't thread-safe, no matter what OpenMP tricks you pull.

(Reply to this)(Thread)


[info]brooksmoses
2008-04-29 12:15 am UTC (link)
This is just a simple prototype, in which I'm doing nearly-trivial things with shared memory and no need for inter-thread synchronization. I'll definitely be looking at OpenMP and such if/when it gets complicated in the actual version, though.

(Reply to this)(Parent)(Thread)


[info]technolope
2008-04-29 12:19 am UTC (link)
OK. I always pictured OpenMP as the easy way to go multithreaded, and pthreads to be the backup method if OMP can't do what you want.

If you're going to be doing a lot of parallel programming in the future, I'd suggest the book "Patterns for Parallel Programming" as a good intro to the concepts and to OMP/MPI (the two methods that all the big labs use).

(Reply to this)(Parent)


[info]elisteran
2008-04-29 09:59 am UTC (link)
If you're going to be using shared memory, perhaps you can do it in terms of shared mmap regions and separate processes instead? One of the things about pthreads is how easy it is for separate threads to be modifying shared state.

(Reply to this)(Parent)


[info]bungo
2008-04-29 11:59 am UTC (link)
Heh. I wrote a hello world with pthreads just the other week, after fooling around with MPI years ago. I think I'd rather stick with some higher-level message passing than splash around in the racy deeps. Good luck.

(Reply to this)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…