int spai_line (matrix *A, int col, int spar, int lower_diag, int upper_diag, double tau, matrix *M) { int s,nbq,nnz,dimr,block_width; double scalar_resnorm,block_resnorm,adjust_epsilon; int i,index,pe,len,ierr; int row_address; int *rptr; double *aptr; int j, k, ptr, low_c, up_c, ccol, row; int rlen; int *buf; int *rbuf; double *vbuf; double comp_max, tau_limit = 1 - tau; block_width = A->block_sizes[col]; adjust_epsilon = epsilon*sqrt((double) block_width); if (spar == 1) /* mark elements depending on tau parameter */ { comp_max = 0; /* find maximum in column resp. row if transposed */ for (j=0; j<A->lines->len[col]; j++) { ptr = A->lines->ptrs[col][j]; if (comp_max < fabs( A->lines->A[col][j])) comp_max = fabs( A->lines->A[col][j]); } /* keep diagonal and elements about fraction of maximum */ for (i=0, j=0; j<A->lines->len[col]; j++) { ptr = A->lines->ptrs[col][j]; if (ptr == col + A->my_start_index || fabs(A->lines->A[col][j]/comp_max) > tau_limit) { n1[i] = A->block_sizes[j]; J->ptr[i++] = ptr; } } J->len = i; J->slen = i; dimr = nnz = 0; } else if (spar == 2) /* set diagonals - mind switching cols and rows */ { if ((low_c = col-upper_diag) < 0) low_c = 0; if ((up_c = col+lower_diag) > A->n-1) up_c = A->n-1; for (i=0, j=low_c; j<=up_c; j++,i++) { J->ptr[i] = j; n1[i] = A->block_sizes[j]; } J->len = i; J->slen = i; dimr = nnz = 0; } else /* initial sparsity diagonal */ { J->ptr[0] = col; J->len = 1; J->slen = block_width; n1[0] = block_width; dimr = nnz = 0; } /* compute I */ getrows(A,M,J,I); copyvv(J,J_tilde); for (s=0, nbq = 0, TAU_ptr[0] = 0, /* effectively infinity */ scalar_resnorm=block_resnorm=1000000*epsilon; (s < nbsteps); s++, nbq++) { com_server(A,M); full_matrix(A,M,max_dim, Ahat); n2[s] = I->slen - dimr; /* compute solution -> x, residual, and update QR */ if ((ierr = qr(A,col,nbq,dimr)) != 0) return ierr; nnz = J->len; dimr = J->slen; /* is solution good enough? */ /* Use Froebenius norm */ convert_to_block (res,resb,col,I->ptr,A,max_dim,I->len); block_resnorm = frobenius_norm(resb,block_width,I->slen); if (debug) { fprintf(fptr_dbg," s=%d col=%d of %d block_resnorm=%12.4le\n", s,col,A->n,block_resnorm); fflush(fptr_dbg); } if (spar == 1 /* row population with tau parameter */ || spar == 2) break; /* fixed diagonals - no further ado */ if (block_resnorm <= adjust_epsilon) break; /* Don't bother with last augment_sparsity */ if (s == (nbsteps-1)) break; if (! augment_sparsity(A,M,col,maxapi,block_resnorm)) break; getrows(A,M, J_tilde,I_tilde); deleter(I,I_tilde,A); if (! append(J,J_tilde)) break; /* J <- J U J_tilde */ if (! append(I,I_tilde)) break; /* I <- I U I_tilde */ } if (block_resnorm > adjust_epsilon && spar == 0) { num_bad_cols++; if (message) { fprintf(message, "could not meet tol, col=%d resnorm = %le, adjust_epsilon = %le\n", col+1, block_resnorm/sqrt((double) block_width), adjust_epsilon); fflush(message); } } if (resplot_fptr) { for (i=0; i<block_width; i++) { if (block_resnorm <= adjust_epsilon) block_flag = " "; else block_flag = "*"; scalar_resnorm = frobenius_norm(&res[i*max_dim],1,I->slen); if (scalar_resnorm <= epsilon) scalar_flag = " "; else scalar_flag = "*"; fprintf(resplot_fptr,"%6d %5.3lf %s %6d %5.3lf %s\n", start_col+i, scalar_resnorm, scalar_flag, col, block_resnorm/sqrt((double) block_width), block_flag); } start_col += block_width; } /* current solution in x, up to nnz, written to M(k,:) */ /* convert x to block structure */ convert_to_block (x,xb,col,J->ptr,A,max_dim,nnz); put_Mline(A,M, col, J->ptr, xb, nnz, J->slen); for (i=0; i<nbsteps; i++) { if (Qlist[i]) { free(Qlist[i]); Qlist[i] = NULL; } else break; } return 0; }
int executecmd(char *linea) { char *cmd; char *arg1; char *arg2; char *search=" "; // Separa el comando y los dos posibles argumentos cmd=strtok(linea," "); arg1=strtok(NULL," "); arg2=strtok(NULL," "); // No hay comando if(cmd==NULL) return(1); // comando "exit" if(strcmp(cmd,"exit")==0) return(0); // comando "copy" if(strcmp(cmd,"copy")==0) { if(arg1==NULL && arg2==NULL) { fprintf(stderr,"Error en los argumentos\n"); return(1); } if(!isinvd(arg1) && !isinvd(arg2)) copyuu(&arg1[2],&arg2[2]); else if(!isinvd(arg1) && isinvd(arg2)) copyuv(&arg1[2],arg2); else if(isinvd(arg1) && !isinvd(arg2)) copyvu(arg1,&arg2[2]); else if(isinvd(arg1) && isinvd(arg2)) copyvv(arg1,arg2); } // comando "cat" if(strcmp(cmd,"cat")==0) { if(isinvd(arg1)) catv(arg1); else catu(&arg1[2]); } // comando dir if(strcmp(cmd,"dir")==0) { if(arg1==NULL) dirv(); else if(!isinvd(arg1)) diru(&arg1[2]); } }