Biomedical Engineering Reference
In-Depth Information
50: void compute() {
51: float Data[NVOLS][NVOXELS], correlation, sum;
52: int mpi_size, mpi_rank, i, j, k, voxel_pair[2];
53:
54: MPI_Bcast(Data, NVOLS*NVOXELS, MPI_FLOAT, 0,
55: MPI_COMM_WORLD);
56: MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
57: MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
58:
59: Normalize(Data);
60:
61: sum = 0;
62: for (i = (mpi_rank - 1); i < NVOXELS; i += mpi_size$){$
63: for (j = 0; j < i; j++) {
64: correlation = 0;
65: for (k = 0; k < NVOLS; k++) {
66: correlation += Data[k][i] * Data[k][j];
67: }
68: correlation = correlation / NVOLS;
69: sum += fabs(correlation);
70: if (fabs(correlation) > THRESHOLD) {
71: voxel_pair[0] = i; voxel_pair[1] = j;
72: MPI_Send(voxel_pair, 2, MPI_INT, 0, PAIR_TAG,
73: MPI_COMM_WORLD);
74: MPI_Send(&correlation, 1, MPI_REAL, 0, \
75: CORRELATION_TAG, MPI_COMM_WORLD);
76: } } }
77: voxel_pair[0] = -1;
78: MPI_Send(voxel_pair, 2, MPI_INT, 0, PAIR_TAG,
79: MPI_COMM_WORLD);
80: MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_REAL,
81: MPI_SUM, MPI_COMM_WORLD);
82: }
Figure 5.17 Function compute of the program correlations.c.
programs should ensure that none of the processes in the group get blocked in-
definitely waiting for an I/O or a blocking send/receive operation to complete. For
example, before calling MPI Bcast , a process should never get blocked waiting for
a message that will be sent by another process after it comes out of MPI Bcast .
Such situations are likely to end up in deadlocks.
In general, for any collective operation, all the processes in the group are
required to make call to the same collective function, with a consistent set of
arguments. For example, in the program above, every MPI process in the group
should call MPI Bcast , with the same root node and the same communicator.
For efficiency, all the processes in the group should call this function nearly at the
same time, otherwise the last process to call this function may cause all the other
processes to wait, thereby wasting computational resources.
Search WWH ::




Custom Search