/* adjusts max values across shared values x */ void Coupler::max(dim_t n, double* x) { const dim_t overlap_n = getNumOverlapValues(); const dim_t my_n = n - overlap_n; startCollect(x); double* remote_values = finishCollect(); #pragma omp parallel for for (dim_t i=0; i < overlap_n; ++i) x[my_n+i] = std::max(x[my_n+i], remote_values[i]); }
void SystemMatrix::balance() { const dim_t nrow = getTotalNumRows(); if (!is_balanced) { if ((type & MATRIX_FORMAT_CSC) || (type & MATRIX_FORMAT_OFFSET1)) { throw PasoException("SystemMatrix_balance: No normalization " "available for compressed sparse column or index offset 1."); } if (getGlobalNumRows() != getGlobalNumCols() || row_block_size != col_block_size) { throw PasoException("SystemMatrix::balance: matrix needs to be a square matrix."); } // calculate absolute max value over each row #pragma omp parallel for for (dim_t irow=0; irow<nrow; ++irow) { balance_vector[irow]=0; } mainBlock->maxAbsRow_CSR_OFFSET0(balance_vector); if (col_coupleBlock->pattern->ptr != NULL) { col_coupleBlock->maxAbsRow_CSR_OFFSET0(balance_vector); } // set balancing vector #pragma omp parallel for for (dim_t irow=0; irow<nrow; ++irow) { const double fac = balance_vector[irow]; if (fac > 0) { balance_vector[irow]=sqrt(1./fac); } else { balance_vector[irow]=1.; } } ///// rescale matrix ///// // start exchange startCollect(balance_vector); // process main block mainBlock->applyDiagonal_CSR_OFFSET0(balance_vector, balance_vector); // finish exchange double* remote_values = finishCollect(); // process couple block if (col_coupleBlock->pattern->ptr != NULL) { col_coupleBlock->applyDiagonal_CSR_OFFSET0(balance_vector, remote_values); } if (row_coupleBlock->pattern->ptr != NULL) { row_coupleBlock->applyDiagonal_CSR_OFFSET0(remote_values, balance_vector); } is_balanced = true; } }
void Coupler::fillOverlap(dim_t n, double* x) { const dim_t overlap_n = getNumOverlapValues(); const dim_t my_n= n - overlap_n; const dim_t offset = block_size * my_n; startCollect(x); double* remote_values = finishCollect(); #pragma omp parallel for for (dim_t i=0; i < overlap_n * block_size; ++i) { x[offset+i] = remote_values[i]; } }
/* * Private attribute-adding code * most of the work here is normalizing the value, which is the same * as regular normalization except for " is replaced by """ */ static genxStatus addAttribute(genxAttribute a, constUtf8 valuestr) { utf8 lastv = (utf8) valuestr; genxWriter w = a->writer; /* if valuestr not provided, this is an xmlns with a pre-cooked value */ if (valuestr) { startCollect(&a->value); while (*valuestr) { int c = genxNextUnicodeChar(&valuestr); if (c == -1) return w->status = GENX_BAD_UTF8; if (!isXMLChar(w, c)) return w->status = GENX_NON_XML_CHARACTER; switch(c) { case 9: collectPiece(w, &a->value, "	", 5); break; case 0xa: collectPiece(w, &a->value, "
", 5); break; case 0xd: collectPiece(w, &a->value, "
", 5); break; case '"': collectPiece(w, &a->value, """, 6); break; case '<': collectPiece(w, &a->value, "<", 4); break; case '&': collectPiece(w, &a->value, "&", 5); break; /* case '>': collectPiece(w, &a->value, ">", 4); break; */ default: collectPiece(w, &a->value, (const char *) lastv, valuestr - lastv); break; } lastv = (utf8) valuestr; } endCollect(&a->value); } /* now add the namespace attribute; might fail if it's bee hand-declared */ if (a->ns) addNamespace(a->ns, NULL); if (valuestr && a->provided) return w->status = GENX_DUPLICATE_ATTRIBUTE; a->provided = 1; return GENX_SUCCESS; }