Example #1
0
int main(int argc, char* argv[])
{
    PI_PROCESS* q;
    PI_PROCESS* r;

    PI_Configure(&argc, &argv);

    q = PI_CreateProcess(proc_q, 0, NULL);
    r = PI_CreateProcess(proc_r, 0, NULL);
    main_q = PI_CreateChannel(PI_MAIN, q);
    q_r = PI_CreateChannel(q, r);
    r_main = PI_CreateChannel(r, PI_MAIN);

    PI_StartAll();

    PI_Write(main_q, "%d", 0);

    PI_StopMain(0);
    return 0;
}
Example #2
0
/*
	Creates the workers. Setups up channels from the workers to PI_MAIN.
	Setups up channels to the workers from PI_Main. Bundles the channels
	from the workers to PI_Main.
*/
void SetupWorkers(int workerCount){
	int i;

	// If there are no workers, we have nothing to setup, so just leave.
	if(workerCount == 0){return;}

	Worker = malloc( workerCount * sizeof(PI_PROCESS*) );
	toWorker = malloc( workerCount * sizeof(PI_CHANNEL*) );
	result = malloc( workerCount * sizeof(PI_CHANNEL*) );

	for ( i=0; i<workerCount; i++ ) {
		Worker[i] = PI_CreateProcess( workerFunc, i, NULL );
		toWorker[i] = PI_CreateChannel( PI_MAIN, Worker[i] );
		result[i] = PI_CreateChannel( Worker[i], PI_MAIN );
	}

	fromWorkerBundle = PI_CreateBundle(PI_SELECT, result, workerCount);
}
Example #3
0
int main( int argc, char *argv[] ) {
    int i, sum;
    int send[5];
    int recv[5 * NUM_CHANS];
    float avg;

    for ( i = 0; i < 5; i++ ) {
        send[i] = i + 1;
    }

    PI_Configure( &argc, &argv );

    for ( i = 0; i < NUM_PROCS; i++ ) {
        procs[i] = PI_CreateProcess( WorkFunc, i, NULL );
        chans[i] = PI_CreateChannel( PI_MAIN, procs[i] );
        chans_out[i] = PI_CreateChannel( procs[i], PI_MAIN );
    }
    broadcast_bundle = PI_CreateBundle( PI_BROADCAST, chans, NUM_CHANS );
    gather_bundle = PI_CreateBundle( PI_GATHER, chans_out, NUM_CHANS );

    PI_StartAll();

    PI_Broadcast( broadcast_bundle, "%5d", send );
    PI_Gather( gather_bundle, "%5d", recv );

    sum = 0;
    for ( i = 0; i < 5 * NUM_CHANS; i++ ) {
        sum += recv[i];
    }
    avg = sum / ( 5.0f * NUM_CHANS );

    printf( "\nThe average was: %f\n", avg );

    PI_StopMain( 0 );
    return 0;
}