예제 #1
0
static int init(void)
{
    int argc = default_argc;
    char** argv = default_argv;
    PI_QuietMode = 1;
    PI_OnErrorReturn = 1;

    PI_Configure(&argc, &argv);

    // Add your initialization code here.

    PI_StartAll();
    return 0;
}
예제 #2
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;
}
예제 #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;
}
예제 #4
0
파일: pal.c 프로젝트: andrewdownie/CIS3090
int main( int argc, char *argv[] )
{
	FILE *output, *input;	// File pointers for the data that will be read in and written out.
	double programRunTime; 	// The amount of time a this program took to complete execution.
	int processCount;		// The total number of processes we have including PI_Main.
	int workerCount;		// The max number of workers this program run can utilize.

	// Setup our program, calculate how many workers we have.
	processCount = PI_Configure( &argc, &argv );
	workerCount = processCount - 1;

	PI_StartTime();

	if(argc != 2){ // If after setting up our program, we don't have a string for a file argument, abort this run.
		return ExitFailure(", Error: No input file specified.", __FILE__, __LINE__);
	}

	// Create the workers based off worker count, and the channels/bundles between the workers and PI_Main.
	SetupWorkers(workerCount);

	//**********//
	PI_StartAll();
	//**********//

	// File opening
	output = fopen("pal.out", "a");
	input = fopen(argv[1], "r");

	// File error checking.
	if(output==NULL){
		return ExitFailure("Could not open output file 'pal.out' for appending in current directory.", __FILE__, __LINE__);
	}
	if(input==NULL){
		return ExitFailure("Could not open input file for reading, from path in argv[1].", __FILE__, __LINE__);
	}
	else{
		printf(">> Input file is: '%s'\n", argv[1]);
	}


	// Run serial or parallel algorithm.
	if(workerCount == 0){
		Serial(input, output);
	}
	else{
		Parallel(input, output, workerCount);
	}

	// Clean up our program run.
	fclose(output);
	fclose(input);

	free(toWorker);
	free(Worker);
	free(result);

	printf(">> Exiting... <<\n");

	programRunTime = PI_EndTime();
	printf("\n\n>>< PROGRAM EXECUTION TIME: (%.2f)s ><<\n\n\n", programRunTime);
	PI_StopMain(0);
	return EXIT_SUCCESS;
}