HP MLIB User's Guide Vol. 2 7th Ed.

760 HP MLIB LAPACK User’s Guide
Sample programs
/* Set up row pointers */
rowptr[0] = 0;
fst_row = iam * m_loc_fst;
nnz_loc = 0;
for (j = 0; j < m_loc; ++j) {
row = fst_row + j;
rowptr[j+1] = rowptr[j] + marker[row];
marker[j] = rowptr[j];
}
nnz_loc = rowptr[m_loc];
if (!(nzval_loc=(double *) malloc(nnz_loc*sizeof(double)))) {
printf(“malloc fails for nzval_loc[]\n”);
exit (-1);
}
if (!( colind= (int_t *) malloc(nnz_loc * sizeof(int_t)))) {
printf(“malloc fails for colind[]\n”);
exit (-1);
}
/* Transfer the matrix into the compressed row storage */
for (i = 0; i < n; ++i) {
for (j = colptr[i]; j < colptr[i+1]; ++j) {
row = rowind[j];
if ( (row>=fst_row) && (row<fst_row+m_loc) ) {
row = row - fst_row;
relpos = marker[row];
colind[relpos] = i;
nzval_loc[relpos] = nzval[j];
++marker[row];
}
}
}
/* Destroy GA */
free(((NCformat *)GA.Store)->rowind);
free(((NCformat *)GA.Store)->colptr);
free(((NCformat *)GA.Store)->nzval);
free(GA.Store);
/* Set up the local A in NR_loc format */
A.Stype = SLU_NR_loc;
A.Dtype = SLU_D;
A.Mtype = SLU_GE;
A.nrow = m;
A.ncol = n;
if ( !(A.Store = (void *) malloc(sizeof(NRformat_loc))) ) {
printf(“malloc fails for A.Store[]\n”);
exit (-1);
}