Example #1
0
 /************* Constructor, destructor ***********************************/
 em2d(const int _IE, const int _JE)
 {
      IE = _IE;
      JE = _JE;
      allocate_2D(&Dz,IE,JE);
      
      for(int j=0; j < JE; j++ ) 
           for(int i=0; i < IE; i++ ) 
                Dz[i][j] = 0.0, printf("Dz[%d][%d] = %f\n",i,j,Dz[i][j]);
 }
Example #2
0
File: x86_sor.c Project: valner/svt
INT main(INT argc, CHAR *argv[]) {
/********** MAIN PROGRAM *********************************
 * Solve Laplace equation using Jacobi iteration method  *
        *
 *********************************************************/
      INT m = M_DEFAULT, mp, k, p, below, above;
      long iter=MAXSTEPS;
      REAL TOL=EPS_DEFAULT, del, gdel,start,finish,mytime;
      CHAR line[80];
      REAL **v, **vt, **vnew;

      
      k = 0; 
      p= 1;
      if(k == 0) {
          fprintf(OUTPUT," Number of args in command line, argc :\n");
          
          fprintf(OUTPUT," argc = %d :\n", argc);
          if (argc >= 2) 
              fprintf(OUTPUT," arg[1]= %s :\n", argv[1]);
          if (argc >= 3) 
              fprintf(OUTPUT," arg[2]= %s :\n", argv[2]);
          
          if (argc >1){
              m=atoi(argv[1]);
              m=MAX_M;
          }  
          
          if (argc >2 ) {
              TOL= atof(argv[2]);
              TOL=EPS;
          }
          
          fprintf(OUTPUT,"Size of interior points, m :\n");
          fprintf(OUTPUT,"m = %d\n",m);
          fprintf(OUTPUT,"Numerical accuracy, eps :\n");
          fprintf(OUTPUT,"eps = %f\n",TOL);

          fprintf(OUTPUT,"Number of processes, p :\n");
          fprintf(OUTPUT,"p = %d\n",p);
          
          start=-time(0);
      }
      
      mp = m/p;
      
      v  = allocate_2D(m, mp);  /* allocate mem for 2D array */
      vt = allocate_2D(mp, m);
      vnew = allocate_2D(mp, m);

      gdel = 1.0;
      iter = 0;

      bc(m, mp, v, k, p); /* initialize and define B.C. for v */
      transpose(m, mp, v, vt);  /* solve for vt */
                                /* driven by need of update_bc_2 */

      replicate(mp, m, vt, vnew);            /* vnew = vt */
      
      REAL ro = 1.0 - pow (PI / (2 * (m + 1)), 2);
      REAL w = 0;
      while (gdel > TOL) {  /* iterate until error below threshold */
        iter++;             /* increment iteration counter */

        if(iter > MAXSTEPS) {
          fprintf(OUTPUT,"Iteration terminated (exceeds %6d", MAXSTEPS);
          fprintf(OUTPUT," )\n");
          return (0);       /* nonconvergent solution */
        }
/* compute new solution according to the Jacobi scheme */
        /*update_jacobi(mp, m, vt, vnew, &del);  [> compute new vt <]*/
        update_sor(mp, m, vt, vnew, &del, w);
        update_w(&w, ro);
            if (del > gdel)
                gdel = del;
          if( k == 0) {
            fprintf(OUTPUT,"iter,del,gdel: %6d, %lf %lf\n",iter,del,gdel);
        }
        update_bc_2( mp, m, vt, k, below, above); /* update b.c. */
      }
      if (k == 0) {
	  finish=time(0);
        mytime=start+finish;
        fprintf(OUTPUT,"Stopped at iteration %d\n",iter);
        fprintf(OUTPUT,"The maximum error = %f\n",gdel);
        fprintf(OUTPUT,"Time = %f\n",mytime);

      }
      if (FILE_OUT) {
	  /* write v to file for use in MATLAB plots */
	  transpose(mp, m, vt, v);
	  write_file( m, mp, v, k, p );
	  
      }

      free(v); free(vt); free(vnew); /* release allocated arrays  */
      
      return (0);
}
int do_each_mnpt(char *rp_name, time_t update_time , int(*function)(char *, time_t))
{
	// Assumes that total restore is needed restore everything in different folders 
	
	char mount_info_file[]="/proc/mounts";
	char filesystems_info_file[]="/proc/filesystems";
	
	char *partition_types[PARTITION_COUNT],*partition_list[PARTITION_COUNT];
	char *mount_dir;
	int i,count, mounts_count, err;
	FILE *mount_file,*partition_file;
	struct stat st;
	
	mount_file=fopen(mount_info_file,"r");
	if(!mount_file)
	{
		perror("unable to open mount_file");
		//exit
	}
	
	partition_file=fopen(filesystems_info_file,"r");
	if(!partition_file)
	{
		perror("unable to open partition_file");
		//exit
	}
	
	allocate_2D(partition_types,PARTITION_COUNT,SZ);
	
	count = parse_partition_types(partition_file,partition_types,PARTITION_COUNT);
	
/*
	printf("\ncount=%d",count);
	for(i=0;i<count;i++)
	{
		printf("\n%s",partition_types[i]);
	}
*/
	
	allocate_2D(partition_list,PARTITION_COUNT,SZ);
	
	mounts_count = read_mount_list(partition_list,PARTITION_COUNT,partition_types,count);
	
	mount_dir = (char*)malloc(SZ);
	

	printf("\nmounts_count=%d",mounts_count);
	for(i=0;i<mounts_count;i++)
	{
		printf("\nmount_point=%s",partition_list[i]);
		printf("\nTrying to restore backup from this mountpoint");
		snprintf(mount_dir,SZ,"%s/%s",partition_list[i],SAVE_DIR);
		err = stat(mount_dir,&st);
		if(err)
		{
			perror("Error");
		}
		else
		{
			function(partition_list[i],update_time);
		}
		
	}	
	
	free_2D(partition_types,PARTITION_COUNT);
	free_2D(partition_list,PARTITION_COUNT);
	free(mount_dir);
	sleep(10);
	return 0;
}