Saturday, January 12, 2008

More mac and linux -- parallelization

My company just bought a bunch of 8-core workstations -- it is high time to work on programs that take advantage of a modern computing environment.


I had written a renderer that used pthread and semaphores to partition and then manage the job, so I thought I'd see if I could do the same thing on my mac.  Unfortunately, I had used unnamed semaphores (sem_init(...)) on my Linux boxes, and the program failed (all threads appeared to be finished immediately) on the Leopard box.


Turns out that when you examine the error return, sem_init() has an entry point and prototype in the library and header file respectively, but it's actually "Not Implemented".  So, I switched over to named semaphores, and it all works perfectly.

In particular, on my 8-core box, I was getting some 6x speedup.


// start the threads
for(thread_id = 0; thread_id < n_proc; thread_id++) {
char sem_name[64];
printf("Starting thread %d\n", thread_id);
sprintf(sem_name, "sem_%d\n", thread_id);
if((semaphore[thread_id] = sem_open(sem_name, O_CREAT, 0777, 0)) == SEM_FAILED) {
printf("sem_open failed\n");
perror("sem_open error: ");
return -1;
}
ret = pthread_create(&thread[thread_id], NULL, (void *)median_scanlines, (void *)thread_id);
}

// wait for all threads to finish -- when thread is done, it calls sem_post(), then sem_wait below will unblock
for(thread_id = 0; thread_id < n_proc; thread_id++) {
printf("Waiting for thread %d to finish\n", thread_id);
sem_wait(semaphore[thread_id]);
}


Wednesday, January 09, 2008

just a little terminal icon



I hated the busy, but still low contrast, icon that comes with the very nice iTerm program I use on my MacBook Pro, so I found one on the 'net from an fphilipe, and made a tiff file that had alpha, to use as the icon, and it looks a lot sweeter.  Here it is, as two jpeg files (as Blogger won't let me post a TIFF file)