Example program: tpa1

The following example program tpa1 is used in the sections above to show the basic performance statistics that can be collected and displayed without instrumentation of the code.

tpa1.c is the source code for the PPE, which spawns three copies of program tpa1_spu on SPEs 0, 1 and 2. The code in tpa1_spu executes the for-loop a different number of times in each of the SPEs. For each SPE, the loop is executed three times the number passed in as the parameter.
// file tpa1.c - error checking removed to improve readability

	...

	// the value of nr_spus is 3
	for (i = 0; i < nr_spus; i++) {
    spe_context_ptr_t spe;
    spe_program_handle_t *tpa1_spu;
    unsigned int entry = SPE_DEFAULT_ENTRY;
    union {
			void *ptr;
			unsigned int spe_num;
		} t_info;
		
   spe = spe_context_create(0, NULL);
   tpa1_spu = spe_image_open("tpa1_spu")
   (void)spe_program_load(spe, &tpa1_spu);
   printf("Spawning thread:  %d\n", i);
   t_tinfo.spe_num = i;
   (void)spe_context_run(spe, &entry, 0, t_info.ptr, NULL, NULL);
   (void)spe_context_detroy(spe);
	}


  // file tpa1_spu.c

	main(unsigned long long id, unsigned long long spe_num) 
	{
		int i;

		for( i=0; i<spe_num*3; i++ )
		  sim_printf("SPE#: %lld, Count: %d\n", spe_num, i);
	}