int main(void) { unit_t u; set_unit(&u); printf("number: %d\nmsg:%s\n", u.number, u.msg); return 0; }
/** * @brief Permite liberar una unidad de memoria. * @param addr Dirección de memoria dentro del área a liberar. @verbatim Verifica si la direccion que recibe es menor a la direccion del kernel o no, de ser asi sale sin realizar ninguna accion, caso contrario se convierte a una direccion lineal para posteriormente colocarla en el mapa de bits como una unidad disponible. @endverbatim*/ void free_unit(char * addr) { unsigned int start; unsigned int entry; int offset; unsigned int unit; start = round_down_to_memory_unit((unsigned int)addr); if (start < allowed_free_start) {return;} unit = start / MEMORY_UNIT_SIZE; set_unit(unit); /* Marcar la unidad recien liberada como la proxima unidad * para asignar */ next_free_unit = unit; /* Aumentar en 1 el numero de unidades libres */ free_units ++; }
int main() { pamatrix a, acopy, l, ld, r, q, qr; pavector x, b, tau; uint rows, cols; real error; rows = 8; cols = 5; (void) printf("----------------------------------------\n" "Check random %u x %u Cholesky factorization\n", rows, rows); (void) printf("Creating random self-adjoint positive definite matrix\n"); a = new_amatrix(rows, rows); random_spd_amatrix(a, 1.0); (void) printf("Creating random solution and right-hand side\n"); x = new_avector(rows); random_avector(x); b = new_avector(rows); clear_avector(b); mvm_amatrix_avector(1.0, false, a, x, b); (void) printf("Copying matrix\n"); acopy = new_amatrix(rows, rows); copy_amatrix(false, a, acopy); (void) printf("Computing Cholesky factorization\n"); choldecomp_amatrix(a); (void) printf("Solving\n"); cholsolve_amatrix_avector(a, b); add_avector(-1.0, x, b); error = norm2_avector(b); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; (void) printf("Building triangular factor\n"); l = new_amatrix(rows, rows); copy_lower_amatrix(a, false, l); (void) printf("Checking factorization\n"); copy_amatrix(false, acopy, a); addmul_amatrix(-1.0, false, l, true, l, a); error = normfrob_amatrix(a); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; del_amatrix(l); del_amatrix(acopy); del_avector(b); del_avector(x); del_amatrix(a); (void) printf("----------------------------------------\n" "Check random %u x %u LDL^T factorization\n", rows, rows); (void) printf("Creating random self-adjoint positive definite matrix\n"); a = new_amatrix(rows, rows); random_spd_amatrix(a, 1.0); (void) printf("Creating random solution and right-hand side\n"); x = new_avector(rows); random_avector(x); b = new_avector(rows); clear_avector(b); mvm_amatrix_avector(1.0, false, a, x, b); (void) printf("Copying matrix\n"); acopy = new_amatrix(rows, rows); copy_amatrix(false, a, acopy); (void) printf("Computing LDL^T factorization\n"); ldltdecomp_amatrix(a); (void) printf("Solving\n"); ldltsolve_amatrix_avector(a, b); add_avector(-1.0, x, b); error = norm2_avector(b); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; (void) printf("Building triangular factor\n"); l = new_amatrix(rows, rows); copy_lower_amatrix(a, true, l); (void) printf("Multiplying by diagonal\n"); ld = new_amatrix(rows, rows); copy_amatrix(false, l, ld); diageval_amatrix(true, a, true, ld); (void) printf("Checking factorization\n"); copy_amatrix(false, acopy, a); addmul_amatrix(-1.0, false, ld, true, l, a); error = normfrob_amatrix(a); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; del_amatrix(ld); del_amatrix(l); del_amatrix(acopy); del_avector(b); del_avector(x); del_amatrix(a); (void) printf("----------------------------------------\n" "Check random %u x %u LR factorization\n", rows, rows); (void) printf("Creating random invertible matrix\n"); a = new_amatrix(rows, rows); random_invertible_amatrix(a, 1.0); (void) printf("Creating random solution and right-hand side\n"); x = new_avector(rows); random_avector(x); b = new_avector(rows); clear_avector(b); mvm_amatrix_avector(1.0, false, a, x, b); (void) printf("Copying matrix\n"); acopy = new_amatrix(rows, rows); copy_amatrix(false, a, acopy); (void) printf("Computing LR factorization\n"); lrdecomp_amatrix(a); (void) printf("Solving\n"); lrsolve_amatrix_avector(a, b); add_avector(-1.0, x, b); error = norm2_avector(b); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; (void) printf("Building triangular factors\n"); l = new_amatrix(rows, rows); r = new_amatrix(rows, rows); copy_lower_amatrix(a, true, l); copy_upper_amatrix(a, false, r); (void) printf("Checking factorization\n"); copy_amatrix(false, acopy, a); addmul_amatrix(-1.0, false, l, false, r, a); error = normfrob_amatrix(a); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; /* Check forward/backward substitution */ (void) printf("----------------------------------------\n"); check_triangularsolve(true, true, false, l, false); check_triangularsolve(true, true, false, l, true); check_triangularsolve(true, true, true, l, false); check_triangularsolve(true, true, true, l, true); check_triangularsolve(true, false, false, l, false); check_triangularsolve(true, false, false, l, true); check_triangularsolve(true, false, true, l, false); check_triangularsolve(true, false, true, l, true); check_triangularsolve(false, false, false, r, false); check_triangularsolve(false, false, false, r, true); check_triangularsolve(false, false, true, r, false); check_triangularsolve(false, false, true, r, true); set_unit(r); check_triangularsolve(false, true, false, r, false); check_triangularsolve(false, true, false, r, true); check_triangularsolve(false, true, true, r, false); check_triangularsolve(false, true, true, r, true); /* Intermediate clean-up */ (void) printf("Cleaning up\n"); del_amatrix(r); del_amatrix(l); /* Check triangular matrix multiplication */ (void) printf("----------------------------------------\n"); check_triangularaddmul(false, false, false, false); check_triangularaddmul(true, false, false, false); check_triangularaddmul(false, true, false, false); check_triangularaddmul(true, true, false, false); check_triangularaddmul(false, false, true, false); check_triangularaddmul(true, false, true, false); check_triangularaddmul(false, true, true, false); check_triangularaddmul(true, true, true, false); check_triangularaddmul(false, false, false, true); check_triangularaddmul(true, false, false, true); check_triangularaddmul(false, true, false, true); check_triangularaddmul(true, true, false, true); check_triangularaddmul(false, false, true, true); check_triangularaddmul(true, false, true, true); check_triangularaddmul(false, true, true, true); check_triangularaddmul(true, true, true, true); /* Checking QR factorization */ (void) printf("----------------------------------------\n" "Check square QR factorization\n"); copy_amatrix(false, acopy, a); random_avector(x); clear_avector(b); mvm_amatrix_avector(1.0, false, a, x, b); tau = new_avector(rows); qrdecomp_amatrix(a, tau); (void) printf("Solving\n"); qrsolve_amatrix_avector(a, tau, b); add_avector(-1.0, x, b); error = norm2_avector(b); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; q = new_amatrix(rows, rows); qrexpand_amatrix(a, tau, q); (void) printf("Checking factorization\n"); r = new_amatrix(rows, rows); copy_upper_amatrix(a, false, r); qr = new_amatrix(rows, rows); copy_amatrix(false, acopy, qr); addmul_amatrix(-1.0, false, q, false, r, qr); error = normfrob_amatrix(qr); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; (void) printf("Checking inverse\n"); copy_amatrix(false, acopy, a); qrinvert_amatrix(a); identity_amatrix(qr); addmul_amatrix(-1.0, false, acopy, false, a, qr); error = normfrob_amatrix(qr); (void) printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; /* Intermediate clean-up */ (void) printf("Cleaning up\n"); del_amatrix(qr); del_amatrix(r); del_amatrix(q); del_avector(tau); del_avector(b); del_avector(x); del_amatrix(acopy); del_amatrix(a); /* Check forward/backward evaluation */ (void) printf("----------------------------------------\n"); a = new_amatrix(rows, cols); random_amatrix(a); check_lowereval(false, false, a, false); check_lowereval(false, false, a, true); check_lowereval(false, true, a, false); check_lowereval(false, true, a, true); check_uppereval(false, false, a, false); check_uppereval(false, false, a, true); check_uppereval(false, true, a, false); check_uppereval(false, true, a, true); set_unit(a); check_lowereval(true, false, a, false); check_lowereval(true, false, a, true); check_lowereval(true, true, a, false); check_lowereval(true, true, a, true); check_uppereval(true, false, a, false); check_uppereval(true, false, a, true); check_uppereval(true, true, a, false); check_uppereval(true, true, a, true); (void) printf("Cleaning up\n"); del_amatrix(a); a = new_amatrix(cols, rows); random_amatrix(a); check_lowereval(false, false, a, false); check_lowereval(false, false, a, true); check_lowereval(false, true, a, false); check_lowereval(false, true, a, true); check_uppereval(false, false, a, false); check_uppereval(false, false, a, true); check_uppereval(false, true, a, false); check_uppereval(false, true, a, true); set_unit(a); check_lowereval(true, false, a, false); check_lowereval(true, false, a, true); check_lowereval(true, true, a, false); check_lowereval(true, true, a, true); check_uppereval(true, false, a, false); check_uppereval(true, false, a, true); check_uppereval(true, true, a, false); check_uppereval(true, true, a, true); (void) printf("Cleaning up\n"); del_amatrix(a); /* Test random QR factorizations */ (void) printf("----------------------------------------\n" "Check full rectangular QR factorization\n"); a = new_amatrix(rows, cols); random_amatrix(a); acopy = new_amatrix(rows, cols); copy_amatrix(false, a, acopy); tau = new_avector(rows); qrdecomp_amatrix(a, tau); q = new_amatrix(rows, rows); r = new_amatrix(rows, cols); qrexpand_amatrix(a, tau, q); copy_upper_amatrix(a, false, r); qr = new_amatrix(rows, cols); copy_amatrix(false, acopy, qr); addmul_amatrix(-1.0, false, q, false, r, qr); error = normfrob_amatrix(qr); printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; del_amatrix(r); del_amatrix(q); (void) printf("Check skinny QR factorization\n"); q = new_amatrix(rows, cols); r = new_amatrix(cols, cols); qrexpand_amatrix(a, tau, q); copy_upper_amatrix(a, false, r); copy_amatrix(false, acopy, qr); addmul_amatrix(-1.0, false, q, false, r, qr); error = normfrob_amatrix(qr); printf(" Accuracy %g, %sokay\n", error, (error < tolerance ? "" : " NOT ")); if (error >= tolerance) problems++; /* Final clean-up */ (void) printf("Cleaning up\n"); del_amatrix(qr); del_amatrix(r); del_amatrix(q); del_avector(tau); del_amatrix(acopy); del_amatrix(a); (void) printf("----------------------------------------\n" " %u matrices and\n" " %u vectors still active\n" " %u errors found\n", getactives_amatrix(), getactives_avector(), problems); return problems; }
PhotoPrintOperation::PhotoPrintOperation() { set_unit(Gtk::UNIT_POINTS); set_use_full_page(); /* We want to handle the margins ourselves */ PhotoPrintOperation::CalcLayout(Cfg->GetPageSetup()); }