Creating the PPU source file
Right click on the PPU project, and select File > New > Source File.
Figure 29. Create another source file
For the Source File field, type ppu.c. Click
Finish.
Figure 30. New source file
The PPU program is much more complicated than the SPU program. It creates
a number of SPU threads, each of which is launched using the embedded SPU
binary (now seen as spe_program_handle_t SPU).
Copy and paste the following source code into your editor, and then save it:
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <libspe.h>
extern spe_program_handle_t SPU;
#define SPU_THREADS 8
int main(int argc, char **argv) {
speid_t spe_ids[SPU_THREADS];
int i, status = 0;
/* Create several SPE-threads to execute 'SPU'. */
for(i=0; i < SPU_THREADS; i++) {
spe_ids[i] = spe_create_thread(0, &SPU, NULL, NULL, -1, 0);
if (spe_ids[i] == 0) {
fprintf(stderr, "Failed spu_create_thread(rc=%d, errno=%d)\n",
spe_ids[i], errno); exit(1); } }
/* Wait for SPU-thread to complete execution. */
for (i=0; i < SPU_THREADS; i++) {
(void)spe_wait(spe_ids[i], &status, 0); }
printf("nThe program has successfully executed.\n");
return (0);
}
|
Figure 31. Edit the source code file



