/* Reset the contents of the texture image buffers in preparation for them being copied into texture objects */ void DomeTextures(void) { BITMAP4 red = {255,0,0,255},blue = {0,0,255,255}; BITMAP4 green = {0,255,0,255}, magenta = {255,0,255,255}; if (texturetop != NULL) free(texturetop); texturetop = (BITMAP4 *)malloc(TEXTURESIZE*TEXTURESIZE*sizeof(BITMAP4)); if (texturebottom != NULL) free(texturebottom); texturebottom = (BITMAP4 *)malloc(TEXTURESIZE*TEXTURESIZE*sizeof(BITMAP4)); if (textureleft != NULL) free(textureleft); textureleft = (BITMAP4 *)malloc(TEXTURESIZE*TEXTURESIZE*sizeof(BITMAP4)); if (textureright != NULL) free(textureright); textureright = (BITMAP4 *)malloc(TEXTURESIZE*TEXTURESIZE*sizeof(BITMAP4)); if (texturetop == NULL || texturebottom == NULL || textureleft == NULL || textureright == NULL) { fprintf(stderr,"Texture read failed\n"); exit(-1); } /* Plain colours */ Erase_Bitmap(texturetop, TEXTURESIZE,TEXTURESIZE,blue); Erase_Bitmap(texturebottom,TEXTURESIZE,TEXTURESIZE,green); Erase_Bitmap(textureleft, TEXTURESIZE,TEXTURESIZE,red); Erase_Bitmap(textureright, TEXTURESIZE,TEXTURESIZE,magenta); }
/* Main program */ int main(){ /* not Locals */ lapack_complex_double *a, *temp, * u, *vt; lapack_int m = M, n = N, lda = LDA, ldu = LDU, ldvt = LDVT, info; /* Local arrays */ //void prtdat(); double *s; double *superb; int svd_count=0; int i, j ,ix ,iy, index, ii, jj ; double x_min, x_max, y_min, y_max, stepx, /* step size for finding gridpoints coordinates in x and y dimension.*/ stepy; double e=0.1; /* Array used for the ploting of * grid, as an input to the * draw_pseudospectra function. */ double *plot; //double plot[n][n]; COLOUR colour; BITMAP4 col,grey = {128,128,128,0}; /* Memory alocations*/ temp = malloc((lda*m)*sizeof(lapack_complex_double)); a = malloc((lda*m)*sizeof(lapack_complex_double)); u = malloc((ldu*m)*sizeof(lapack_complex_double)); vt = malloc((ldvt*n)*sizeof(lapack_complex_double)); s = malloc(m*sizeof(double)); superb = malloc(min(m,n)*sizeof(double)); plot = malloc((NGRID*NGRID)*sizeof(double)); z = malloc((NGRID*NGRID)*sizeof(double _Complex)); //allocating the 2D array data. if ((data = malloc(SCALE*NGRID*sizeof(double *))) == NULL) { fprintf(stderr,"Failed to malloc space for the data\n"); exit(-1); } for (i=0;i<SCALE*NGRID;i++) { if ((data[i] = malloc(SCALE*NGRID*sizeof(double))) == NULL) { fprintf(stderr,"Failed to malloc space for the data\n"); exit(-1); } } for (i=0;i<SCALE*NGRID;i++){ for (j=0;j<SCALE*NGRID;j++){ data[i][j] = 0; // printf("%f\t",data[i][j]); } } /* printf("-------------------------------------------------\n"); printf(" --------------------------------- \n"); printf ("Starting Computing Pseudopsecta of grcar Matrix\n"); printf("Give the doundaries of the 2-dimenional domain\n"); printf("Insert the minimum value of x-axis\n"); clearerr(stdin); scanf("%lf",&x_min); //getchar(); printf("Insert the maximum value of x-axis\n"); scanf("%lf",&x_max); printf("Insert the minimum value of y-axis\n"); scanf("%lf",&y_min); printf("Insert the maximun value of y-axis\n"); scanf("%lf",&y_max); //printf("Give the grid size you want:\n"); //scanf("%d",&n); */ /*if (x_min==0.0)*/ x_min=XMIN; /*if (x_max==0.0)*/ x_max=XMAX; /*if (y_min==0.0)*/ y_min=YMIN; /*if (y_max==0.0)*/ y_max=YMAX; /* Initialize grid */ printf("The size of the domain is: X=[%f-%f] Y=[%f-%f] \n",x_min,x_max,y_min,y_max); stepx=(double)abs(x_max-x_min)/(NGRID-1); stepy=(double)abs(y_max-y_min)/(NGRID-1); printf("To stepx einai %f\n",stepx); printf("To stepy einai %f\n",stepy); for (i =0; i <NGRID*NGRID; i++){ z[i]=x_min+(i/n * stepx)+(y_min + (i%n * stepy))*I; // z[i]=lapack_make_complex_double( i/n,i%n); just for testing //** printf( " (%6.2f,%6.2f)", lapack_complex_double_real(z[i]), lapack_complex_double_imag(z[i]) ); } memset(temp,0,(lda*m)*sizeof(*temp)); memset(a,0,(lda*m)*sizeof(*a)); memset(u,0,(ldu*m)*sizeof(*u)); memset(vt,0,(ldvt*m)*sizeof(*vt)); j=0; for (i = 0; i < lda*m ; i=i+n ){ if(i==0){ a[i]=lapack_make_complex_double( 1,0); a[i+1]=lapack_make_complex_double( 1,0); a[i+2]=lapack_make_complex_double( 1,0); a[i+3]=lapack_make_complex_double( 1,0); } else if(i == (n-3)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); a[i+(j+3)]=lapack_make_complex_double( 1,0); j++; } else if(i == (n-2)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); j++; } else if(i == (n-1)*n ){ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); j++; } else{ a[i+j]=lapack_make_complex_double( -1,0); a[i+(j+1)]=lapack_make_complex_double( 1,0); a[i+(j+2)]=lapack_make_complex_double( 1,0); a[i+(j+3)]=lapack_make_complex_double( 1,0); a[i+(j+4)]=lapack_make_complex_double( 1,0); j++; } } //print_matrix("Entry Matrix A", m, n, a, lda ); for (iy = 0; iy < NGRID*NGRID; iy++){ //printf("temp size %d, a size %d",(lda*m)*sizeof(*temp),(lda*m)*sizeof(*a)); memcpy(temp, a ,(lda*m)*sizeof(*temp)); //~ print_matrix( "Entry Matrix Temp just after memcopy", m, n, temp, lda ); //~ print_matrix( "Entry Matrix A just after memcopy", m, n, a, lda ); // printf( "To z[%d](%6.4f,%6.4f)\n",iy,lapack_complex_double_real(z[iy]),lapack_complex_double_imag(z[iy]) ); for (i = 0; i < lda*m ; i=i+(n+1)){ //~ printf("%d",i); //~ printf( "To a[%d](%6.2f,%6.2f)\t",i, lapack_complex_double_real(a[i]), lapack_complex_double_imag(a[i]) ); //~ printf( "To z[%d](%6.2f,%6.2f)\n",iy,lapack_complex_double_real(z[iy]),lapack_complex_double_imag(z[iy]) ); temp[i]=a[i]-z[iy]; //~ temp[index] = lapack_make_complex_double(lapack_complex_double_real(a[index])-lapack_complex_double_real(z[iy]), lapack_complex_double_imag(a[index])-lapack_complex_double_imag(z[iy]) ); //~ printf( " temp[%d](%6.2f,%6.2f)", i,lapack_complex_double_real(temp[i]), lapack_complex_double_imag(temp[i]) ); //~ printf( "\n"); } //printf("GRCAR MATRIX AFTER SUBSTRACTION (%d,%d)\n",iy/n,iy%n); //~ print_matrix( "Entry Matrix Temp just before", m, n, temp, lda ); /* Executable statements */ //~ print_matrix( "AT THE BEGINING OF THE FOR LOOP", m, n, a, lda ); printf( "LAPACKE_zgesvd (row-major, high-level) Example Program Results(%d,%d)\n",iy/NGRID,iy%NGRID); /* Compute SVD */ info = LAPACKE_zgesvd( LAPACK_ROW_MAJOR, 'N', 'N', m, n, temp, lda, s, NULL, ldu, NULL, ldvt, superb ); svd_count++; //~ //~ print_matrix( "IN THE MIDDLE OF THE FOR LOOP", m, n, a, lda ); //~ print_matrix( "IN THE MIDDLE OF THE FOR LOOP-TEMP", m, n, temp, lda ); /* Check for convergence */ if( info > 0 ) { printf( "The algorithm computing SVD failed to converge.\n" ); exit( 1 ); } /* Print singular values */ if( info == 0){ // printf("Solution\n"); for ( i= 0; i< m; i++ ) { // printf(" s[ %d ] = %f\n", i, s[ i ] ); } } if(s[m-1] <= e){ printf("THIS ELEMENT BELONGS TO PSEUDOSPECTRA (%d,%d):%6.10f\n",(iy/NGRID+1),(iy%NGRID+1),s[m-1]); /*to index tis parapanw ektupwshs anaferetai sto index tou antistoixou mhtrwou apo thn synarthsh ths matlab grcar_example.m*/ //~ plot[iy/n][iy%n]=s[m-1]; plot[iy]=s[m-1]; } //~ else plot[iy/n][iy%n]=0; else plot[iy]=0; //~ print_rmatrix( "Singular values", 1, m, s, 1 ); /* Print left singular vectors */ // print_matrix( "Left singular vectors (stored columnwise)", m, m, u, ldu ); /* Print right singular vectors */ // print_matrix( "Right singular vectors (stored rowwise)", m, n, vt, ldvt ); } prtdat(NGRID, NGRID, plot, "svd.data"); printf("Total number of svd evaluations in the %d,%d grid is:\t %d\n",NGRID,NGRID,svd_count); //giving values to data from plot for (i = 0; i<NGRID*NGRID; i++) data[SCALE*(i/NGRID)][SCALE*(i%NGRID)] = plot[i]; ///////////////// BITMAP4 black = {0,0,0,0}; Draw_Line(image,NGRID,NGRID,x_min,y_min,x_max,y_min,black); ////////////////// //~ contours[0] = 0.1; //~ contours[1] = 0.01; //~ contours[2] = 0.001; //~ contours[3] = 0.0001; //~ contours[4] = 0.00001; if ((image = Create_Bitmap(SCALE*NGRID,SCALE*NGRID)) == NULL) { fprintf(stderr,"Malloc of bitmap failed\n"); exit(-1); } Erase_Bitmap(image,SCALE*NGRID,SCALE*NGRID,grey); /* Not strictly necessary */ for (j=0;j<SCALE*NGRID;j++) { for (i=0;i<SCALE*NGRID;i++) { colour = GetColour(data[i][j],0,0.1,1); ///////////////////////////////////////////// col.r = colour.r * 255; // col.b = colour.b * 255; // Draw_Pixel(image,SCALE*NGRID,SCALE*NGRID,(double)i,(double)j,col); // colour = GetColour(data[i][j],0,0.0001,1); ///////////////////////////////////////////// // col.g = colour.g * 255; Draw_Pixel(image,SCALE*NGRID,SCALE*NGRID,(double)i,(double)j,col); } } /* Finally do the contouring */ CONREC(data,0,SCALE*NGRID-1,0,SCALE*NGRID-1, z,NCONTOUR,contours,drawline); fprintf(stderr,"Drew %d vectors\n",vectorsdrawn); /* Write the image as a TGA file See bitmaplib.c for more details, or write "image" in your own prefered format. */ if ((fp = fopen("image.tga","w")) == NULL) { fprintf(stderr,"Failed to open output image\n"); exit(-1); } Write_Bitmap(fp,image,SCALE*NGRID,SCALE*NGRID,12); fclose(fp); exit(0); } /* End of LAPACKE_zgesvd Example */