- if( !rank ) {
- int **psend ;
- int **precv ;
- psend = (int**)calloc( nProc, sizeof( int *) ) ;
- precv = (int**)calloc( nProc, sizeof( int *) ) ;
- for( i = 0 ; i < nProc ; i++ ) {
- psend[ i ] = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
- precv[ i ] = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
- }
- for( i = 0 ; i < LOOP_COUNT ; i++ ) {
- if (verbose) {
- fprintf( pf, "Master : loop %d\n", i ) ;
- fflush( pf ) ;
- }
- else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
- fprintf( pf, "Master: loop %d\n", i ); fflush( pf );
- }
- for( j = 1 ; j < nProc ; j++ ) {
- if (verbose) {
- fprintf( pf, " read from child %d\n", j ) ;
- fflush( pf ) ;
- }
- status = MPI_Recv( precv[ j ], DATA_SIZE, MPI_INT, j, MP_TAG,
- MPI_COMM_WORLD, MPI_STATUS_IGNORE ) ;
- if (verbose) {
- fprintf( pf, " read from child %d done, status = %d\n", j,
- status ) ;
- fflush( pf ) ;
- }
- }
- for( j = 1 ; j < nProc ; j++ ) {
- if (verbose) {
- fprintf( pf, " send to child %d\n", j ) ;
- fflush( pf ) ;
- }
- status = MPI_Send( psend[ j ], DATA_SIZE - 1, MPI_INT, j,
- MP_TAG, MPI_COMM_WORLD ) ;
- if (verbose) {
- fprintf( pf, " send to child %d done, status = %d\n", j,
- status ) ;
- fflush( pf ) ;
- }
- }
- }
- for( i = 0 ; i < nProc ; i++ ) {
- free( psend[ i ] );
- free( precv[ i ] );
- }
- free( psend );
- free( precv );
- } else {
- int *psend ;
- int *precv ;
- psend = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
- precv = (int*)calloc( DATA_SIZE, sizeof( int ) ) ;
- for( i = 0 ; i < LOOP_COUNT ; i++ ) {
- if (verbose) {
- fprintf( pf, " send to master\n" ) ;
- fflush( pf ) ;
- }
- /*
- else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
- fprintf( pf, "Slave: loop %d\n", i ); fflush( pf );
- }
- */
- status = MPI_Send( psend, DATA_SIZE - 1, MPI_INT, 0, MP_TAG,
- MPI_COMM_WORLD ) ;
- if (verbose) {
- fprintf( pf, " send to master done, status = %d\n", status ) ;
- fflush( pf ) ;
- fprintf( pf, " read from master\n" ) ;
- fflush( pf ) ;
- }
- status = MPI_Recv( precv, DATA_SIZE, MPI_INT, 0, MP_TAG,
- MPI_COMM_WORLD, MPI_STATUS_IGNORE ) ;
- if (verbose) {
- fprintf( pf, " read from master done, status = %d\n", status ) ;
- fflush( pf ) ;
- }
- }
- free( psend );
- free( precv );
+ if (!rank) {
+ int **psend;
+ int **precv;
+ psend = (int **) calloc(nProc, sizeof(int *));
+ precv = (int **) calloc(nProc, sizeof(int *));
+ for (i = 0; i < nProc; i++) {
+ psend[i] = (int *) calloc(DATA_SIZE, sizeof(int));
+ precv[i] = (int *) calloc(DATA_SIZE, sizeof(int));
+ }
+ for (i = 0; i < LOOP_COUNT; i++) {
+ if (verbose) {
+ fprintf(pf, "Master : loop %d\n", i);
+ fflush(pf);
+ }
+ else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
+ fprintf(pf, "Master: loop %d\n", i);
+ fflush(pf);
+ }
+ for (j = 1; j < nProc; j++) {
+ if (verbose) {
+ fprintf(pf, " read from child %d\n", j);
+ fflush(pf);
+ }
+ status = MPI_Recv(precv[j], DATA_SIZE, MPI_INT, j, MP_TAG,
+ MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+ if (verbose) {
+ fprintf(pf, " read from child %d done, status = %d\n", j, status);
+ fflush(pf);
+ }
+ }
+ for (j = 1; j < nProc; j++) {
+ if (verbose) {
+ fprintf(pf, " send to child %d\n", j);
+ fflush(pf);
+ }
+ status = MPI_Send(psend[j], DATA_SIZE - 1, MPI_INT, j, MP_TAG, MPI_COMM_WORLD);
+ if (verbose) {
+ fprintf(pf, " send to child %d done, status = %d\n", j, status);
+ fflush(pf);
+ }
+ }
+ }
+ for (i = 0; i < nProc; i++) {
+ free(psend[i]);
+ free(precv[i]);
+ }
+ free(psend);
+ free(precv);
+ }
+ else {
+ int *psend;
+ int *precv;
+ psend = (int *) calloc(DATA_SIZE, sizeof(int));
+ precv = (int *) calloc(DATA_SIZE, sizeof(int));
+ for (i = 0; i < LOOP_COUNT; i++) {
+ if (verbose) {
+ fprintf(pf, " send to master\n");
+ fflush(pf);
+ }
+ /*
+ * else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
+ * fprintf(pf, "Slave: loop %d\n", i); fflush(pf);
+ * }
+ */
+ status = MPI_Send(psend, DATA_SIZE - 1, MPI_INT, 0, MP_TAG, MPI_COMM_WORLD);
+ if (verbose) {
+ fprintf(pf, " send to master done, status = %d\n", status);
+ fflush(pf);
+ fprintf(pf, " read from master\n");
+ fflush(pf);
+ }
+ status = MPI_Recv(precv, DATA_SIZE, MPI_INT, 0, MP_TAG,
+ MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+ if (verbose) {
+ fprintf(pf, " read from master done, status = %d\n", status);
+ fflush(pf);
+ }
+ }
+ free(psend);
+ free(precv);