/* ---------------------------------------------------------------------
 *  main
 * ---------------------------------------------------------------------
*/
int main(int argc, char** argv) {

    FILE* f;
    long long s;
    long n, b;
    struct rusage rusage;

    /* check command line parameters */
    if (argc < 3) 
        exit(printf("Usage: %s filename blocking-size\n", argv[0]));

    /* open file for update */
    f = fopen(argv[1], "r+");
    if (f == NULL) exit((printf("can't open file %s\n", argv[1]), 1));

    /* compute number s of matrix elements in the file */
    fseeko(f, 0LL, SEEK_END);
    s = ftello(f)/sizeof(item_type);

    /* compute matrix side */
    n = (long)sqrt(s);

    /* check if matrix is squared */
    if (n*n != s) exit((printf("matrix is not squared\n"), 1));

    /* convert block size from string to integer format */
    b = atol(argv[2]);
    if (b > n) b = n;

    /* print info */
    printf("file size: %lld bytes\n", s);
    printf("file offset model: %ld bit\n", (long)sizeof(off_t)*8);
    printf("matrix size: %ld x %ld\n", n, n);
    printf("block size: %ld items\n", b);

    /* in-place transposition of matrix on file */
    printf("transposing matrix...\n");
    mat_transp(f, n, b);

    fclose(f);

    /* print required internal memory */
    getrusage(RUSAGE_SELF, &rusage);
    printf("used internal memory: %ld MB\n",
        rusage.ru_maxrss/(1024*1024));

    return 0;
}
Ejemplo n.º 2
0
Archivo: nterm.c Proyecto: rforge/muste
static int linreg(double *X,double *Y,double *S,double *U,double *T,double *B,double *R,int m,int n) {
// RS REM  int i;
  mat_store(X,T,m,n);
  if (mat_gram_schmidt(S,U,T,m,n,TOLERANCE)<0) {
    sur_print("\nUnable to solve!");
//    showmatrix(X,m,n);    
    WAIT; return(-1);
  }
  mat_transp(T,S,m,n);
  mat_mlt(S,T,Y,n,m,1);
  solve_upper(B,U,S,n,1,TOLERANCE);

  fixmat(B,n);

  return(residual(R,B,Y,X,m,n));
}