HP MLIB User's Guide Vol. 2 7th Ed.
758 HP MLIB LAPACK User’s Guide
Sample programs
colptr[0]=0; colptr[1]=3; colptr[2]=6; colptr[3]=9;
colptr[4]=13; colptr[5]=14;
/* sol_recvcounts and sol_displs store information that will be
used in gathering the global solution to rank 0. */
if (!iam) {
if (!(sol_recvcounts=(int_t *) malloc(grid.nprow *
grid.npcol*sizeof(int_t
)))) {
printf(“malloc fails for sol_recvcounts[]\n”);
exit (-1);
}
if (!(sol_displs=(int_t *) malloc(grid.nprow *
grid.npcol*sizeof(int_t))))
{
printf(“malloc fails for sol_displs[]\n”);
exit (-1);
}
}
/* Compute the number of rows to be distributed to local processes
*/
m_loc = m / (grid.nprow * grid.npcol);
m_loc_fst = m_loc;
if (!iam) {
sol_displs[0]=0;
for (i=0; i < grid.nprow * grid.npcol-1; i++) {
sol_recvcounts[i]=m_loc;
sol_displs[i+1] = sol_displs[i] + sol_recvcounts[i];
}
sol_recvcounts[grid.nprow * grid.npcol-1]=m_loc;
}
/* When m / procs is not an integer */
if ((m_loc * grid.nprow * grid.npcol) != m) {
m_loc = m_loc+1;
m_loc_fst = m_loc;
if (iam == (grid.nprow * grid.npcol - 1))
m_loc = m - m_loc_fst * (grid.nprow * grid.npcol - 1);
if (!iam) {
sol_displs[0]=0;
for (i=0; i < grid.nprow * grid.npcol-1; i++) {
sol_recvcounts[i]=m_loc;
sol_displs[i+1] = sol_displs[i] + sol_recvcounts[i];
}
sol_recvcounts[grid.nprow * grid.npcol-1]=m - m_loc_fst *
(grid.nprow *
grid.npcol - 1);
}