Example #1
0
void main(int argc, char *argv[]) {
    int counter, times;
    if(argc != 2) {
        printf("Get parameter first please!\n");
        return ;
    }
    times = atoi(argv[1]);
    if(times <=0) {
        printf("Get param error\n");
        return;
    }

    init_random();
    init_input();
    init_cells();

    //init_kernel_platform();
    //gettimeofday(&t_start, NULL);
    for(counter=0; counter<times; counter++) {
        run();
    }
    //gettimeofday(&t_end, NULL);
    //close_kernel_platform();

    //printf("exec digital exec success\n");
    //cost_time = (t_end.tv_sec*1000000l+t_end.tv_usec) - (t_start.tv_sec*1000000l+t_start.tv_usec);
    //printf("run Cost time: %lds+%ldus\n", cost_time/1000000, cost_time%1000000);

    close_cells();
    close_random();
    printf("%d times exec over\n", times);
}
Example #2
0
int main(int argc, char **argv)
{
  /* Read command line arguments */
  read_command_line(argc,argv);

  /* Read Parameters from parameter file */
  read_parameters();

  /* read box from file header */
  if (box_from_header) read_box(infilename);

  /* Initialize cell data structures */
  init_cells();

  /* Read coordinates and displacement */
  read_displacement(infilename);

  /* Calculate strain tensor */
  calc_strain();

  /* Output strain tensor */
  write_data();

  return 0;

}
Example #3
0
int main(int argc, char **argv)
{
    int tablesize;
    int n,i,j,k,l;

    /* Read command line arguments */
    read_command_line(argc,argv);

    /* Read Parameters from parameter file */
    read_parameters();

    tablesize = slots*ntypes*ntypes*ntypes*ntypes*sizeof(real);
    histogram = (real *) malloc(tablesize);
    if (NULL==histogram) error("Cannot allocate memory for histograms.");
    hist_dim.n = slots;
    hist_dim.i = ntypes;
    hist_dim.j = ntypes;
    hist_dim.k = ntypes;
    hist_dim.l = ntypes;

    for (n=0; n<slots; ++n)
        for (i=0; i<ntypes; ++i)
            for (j=0; j<ntypes; ++j)
                for (k=0; k<ntypes; ++k)
                    for (l=0; l<ntypes; ++l)
                        *PTR_5D_V(histogram,n,i,j,k,l,hist_dim) = 0.0;

    r2_cut = SQR(r_max);

    /* read box from file header */
    if (box_from_header) read_box(infilename);

    /* Initialize cell data structures */
    init_cells();

    /* Read atoms */
    read_atoms(infilename);

    /* Calculate the torsion angles */
    calc_angles();

    /* Output results */
    write_data();

    return 0;

}
Example #4
0
int		init_world(t_server *server)
{
  u_int		i;

  i = 0;
  fprintf(stdout, "Initializing world...\n");
  if ((server->world = (t_cell **)my_malloc(server->width *
					sizeof(t_cell *), CELL)) == NULL)
    return (-1);
  while (i < server->width)
    {
      if ((server->world[i] = (t_cell *)my_malloc(server->height *
						sizeof(t_cell), CELL)) == NULL)
	return (-1);
      i++;
    }
  if (init_cells(server) == -1)
    return (-1);
  fprintf(stdout, "World initialized\n");
  return (0);
}
Example #5
0
int main()
{
  int gen = 1;

  FILE *fp;

  if ((fp = fopen("cells.txt", "w")) == NULL) {
    fprintf(stderr, "error: cannot open a file.\n");
    return 1;
  }

  init_cells();
  print_cells(fp);

  while (1) {
    printf("generation = %d\n", gen++);
    update_cells();
    print_cells(fp);
  }

  fclose(fp);
}
Example #6
0
int main(int argc, char **argv)
{
  /* Read command line arguments */
  read_command_line(argc,argv);

  /* Read Parameters from parameter file */
  read_parameters();

  /* read box from file header */
  if (box_from_header) read_box(infilename);

#ifdef TERSOFF
  /* Compute Tersoff parameters */
  init_tersoff();
#endif

  /* Initialize cell data structures */
  init_cells();

  /* Read atoms */
  read_atoms(infilename);

  /* Compute neighbour tables */
  do_work(do_neighbour_tables); 
  first = 0;
  do_work(do_neighbour_tables); 

  /* Search for rings */
  search_rings();

  /* Output ring statistics */
  write_data();

  return 0;

}
Example #7
0
int main(int argc, char **argv)

{
  /* Read command line arguments */
  read_command_line(argc,argv);

  /* Read Parameters from parameter file */
  read_parameters();

  /* Initialize cell data structures */
  init_cells();

  /* Read atoms */
  read_stress(infilename);

  /* Calculate volume of Voronoi cells */
  voronoi();

  /* Output results */
  write_stress(restart);

  exit(0);

}
Example #8
0
int main(int argc, char** argv) {

  int rank, size;

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  
  int mpi_lattice_size = lround(sqrt(size));
  
  if(size < 4 || ! (mpi_lattice_size*mpi_lattice_size==size) ) {
    printf("You have to use a square number of MPI processes.");
    MPI_Abort(MPI_COMM_WORLD,1);
  }
  
  if( find_option( argc, argv, "-h" ) >= 0 )
  {
      printf( "Options:\n" );
      printf( "-h to see this help\n" );
      printf( "-n <int> to set the grid size\n" );
      printf( "-o <filename> to specify the output file name\n" );
      MPI_Abort(MPI_COMM_WORLD,1);
  }
  
  int GRIDSIZE = read_int( argc, argv, "-n", DEFAULT_GRIDSIZE );
  // Check gridsize for some basic assumptions
  if(GRIDSIZE%2 || GRIDSIZE%(mpi_lattice_size)) {
    printf("Only even Gridsize allowed and\nGridsize has to be a multiple of the number of MPI procs!\n");
    MPI_Abort(MPI_COMM_WORLD,1);
  }

  FILE *f;

  if(rank==0) {
    char *savename = read_string( argc, argv, "-o", "sample_conduct.txt" );
    f = savename ? fopen( savename, "w" ) : NULL;
    if( f == NULL )
    {
        printf( "failed to open %s\n", savename );
        MPI_Abort(MPI_COMM_WORLD,1);
    }
  }
  

  int my_mpi_i,my_mpi_j;
  int my_gridsize= GRIDSIZE/(mpi_lattice_size);
  int t,i,j;
  double *T, *Tn,*Tf;
  
  my_mpi_j=rank%mpi_lattice_size;
  my_mpi_i=rank/mpi_lattice_size;
  
  // Allocate Grid with a border on every side
  int padded_grid_size = my_gridsize+2;
  if(rank == 0) {
    Tf=(double *) malloc(GRIDSIZE*GRIDSIZE*sizeof(double));
  }
  T=(double *) malloc((padded_grid_size)*(padded_grid_size)*sizeof(double));
  Tn=(double *) malloc((padded_grid_size)*(padded_grid_size)*sizeof(double));
  

  
  // remember -- our grid has a border around it!
  if(rank==0)
    init_cells(Tf,GRIDSIZE);
  else {
    int i,j;
    for (i=0;i<padded_grid_size;i++)
      for(j=0;j<padded_grid_size;j++)
        T[i*padded_grid_size+j]=0;
  }
  
  
  if(rank==0) {
    for(i=0;i<mpi_lattice_size;i++) {
      for(j=0;j<mpi_lattice_size;j++) {
        if(i==0 && j==0) {
          int k,l,m=1,n=1;
          for(k=0;k<padded_grid_size;k++)
            for(l=0;l<padded_grid_size;l++)
              T[k*padded_grid_size+l]=0;
          
          for(k=0;k<my_gridsize;k++) {
          
            for(l=0;l<my_gridsize;l++) {
            
              T[m*padded_grid_size+n]=Tf[k*(GRIDSIZE) + l];
              n++;
            }
            m++;
            n=1;
          }
          continue;
        }
        
        //re-use Tn for temp arrays
        int k,l,m=1,n=1;
        for(k=0;k<padded_grid_size;k++)
          for(l=0;l<padded_grid_size;l++)
            Tn[k*padded_grid_size+l]=0;
        
        for(k=0;k<my_gridsize;k++) {
          for(l=0;l<my_gridsize;l++) {
            Tn[m*padded_grid_size+n]=Tf[(k + my_gridsize*i)*(GRIDSIZE) + l+my_gridsize*j];
            n++;
          }
          m++;
          n=1;
        }
        int dest;
        dest=i*mpi_lattice_size+j;
        // printf("\nDest: %d from %d where %d\n  ",dest,size,mpi_lattice_size);
        MPI_Send(Tn,padded_grid_size*padded_grid_size,MPI_DOUBLE,dest,42,MPI_COMM_WORLD);
      }
    }
  }
  else {
    // printf("\nRank: %d %d %d\n  ",rank,my_mpi_i,my_mpi_j);
    MPI_Recv(T,padded_grid_size*padded_grid_size,MPI_DOUBLE,0,42,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
  }
  
  // printf("\nRank: %d %d %d\n  ",rank,my_mpi_i,my_mpi_j);
  // print(T,padded_grid_size,rank);
  // MPI_Barrier(MPI_COMM_WORLD);
  // exit(1);
  
  

  
  for(t=1;t<=TIMESTEPS;t++) { // Loop for the time steps
  
    // get the neighbors:
    put_neighbor(T,0,1,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    get_neighbor(T,0,-1,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    
    put_neighbor(T,1,0,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    get_neighbor(T,-1,0,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    
    put_neighbor(T,0,-1,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    get_neighbor(T,0,1,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    
    put_neighbor(T,-1,0,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);
    get_neighbor(T,1,0,my_mpi_i,my_mpi_j,mpi_lattice_size,my_gridsize);

    
    MPI_Barrier(MPI_COMM_WORLD);    
    /*
    printf("\nI am: %d\n",rank);
    print(T,padded_grid_size,t);
    printf("\n");
    */



    for(i=1;i<my_gridsize+1;i++) {
      for(j=1;j<my_gridsize+1;j++) {
        
        Tn[i*padded_grid_size + j] = T[(i-1)*padded_grid_size + (j)] + T[(i+1)*padded_grid_size + (j)]
                                   + T[(i)*padded_grid_size + (j-1)] + T[(i)*padded_grid_size + (j+1)];
        Tn[i*padded_grid_size + j] /= 4;
      }
    }

    for(i=1;i<my_gridsize+1;i++) {
      for(j=1;j<my_gridsize+1;j++) {
        T[i*padded_grid_size + j] = Tn[i*padded_grid_size + j];
      }
    }
    
    /*
    MPI_Barrier(MPI_COMM_WORLD);    
    printf("\nI am: %d\n",rank);
    print(T,padded_grid_size,t);
    printf("\n");
    */
    
    if(!(t % PRINTSTEP)) {
    
      if(rank==0) {
        for(i=0;i<mpi_lattice_size;i++) {
          for(j=0;j<mpi_lattice_size;j++) {
            if(i==0 && j==0) {
              int k,l,m=1,n=1;
              for(k=0;k<my_gridsize;k++) {
                for(l=0;l<my_gridsize;l++) {
                  Tf[k*(GRIDSIZE) + l]=T[m*padded_grid_size+n];
                  n++;
                }
                m++;
                n=1;
              }
            }
            else {
              int source=i*mpi_lattice_size+j;
              MPI_Recv(Tn,padded_grid_size*padded_grid_size,MPI_DOUBLE,source,42,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
              //re-use Tn for temp arrays
              int k,l,m=1,n=1;
              for(k=0;k<my_gridsize;k++) {
                for(l=0;l<my_gridsize;l++) {
                  Tf[(k + my_gridsize*i)*(GRIDSIZE) + l+my_gridsize*j]=Tn[m*padded_grid_size+n];
                  n++;
                }
                m++;
                n=1;
              }
            }
          }
        }
      }
      else {
        MPI_Send(T,padded_grid_size*padded_grid_size,MPI_DOUBLE,0,42,MPI_COMM_WORLD);
      }

      if(rank==0) {
         // print(Tf,GRIDSIZE,t);
        save(f,Tf,GRIDSIZE,t);
        printf("Time: %d\n",t);
      }
    }
    
  }
  
  if(rank==0)
    fclose(f);
  
  
    
  MPI_Finalize();
  
  return 0;
}
/* read input graph and construct cell, net arrays */
void read_graph(char fname[],
                int  nocells,
                int  nonets,
                int  noparts,
                int *totsize,
                int *totcellsize,
                int *max_density,
                int *max_cweight,
                int *max_nweight,
                cells_t cells[],
                nets_t  nets[],
                corn_t  cnets[])
{
    FILE *fp;
    open_file(&fp, fname, "r");

    /* graph size is already read so re-read and discard. */
    int ignore1, ignore2;
    if (fscanf(fp, "%d%d", &ignore1, &ignore2) == EOF) {
        printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
        close_file(&fp);
        exit(1);
    } 

    /* initialize cells array */
    init_cells(nocells, cells);

    /* read nets */
    *max_nweight = -1;
    *totsize = 0;
    for (int i = 0; i < nonets; i++) {
        int ignore;  /* this is the number of pins on this net; it
                        makes sense for hypergraphs; for graphs, it is
                        always 2. */
        if (fscanf(fp, "%d%d%d%d", &nets[i].nweight, &ignore, &nets[i].ncells[0], &nets[i].ncells[1]) == EOF) {
            printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
            close_file(&fp);
            exit(1);
        }
        /* temp for reading 2, the net degree */
        cells[nets[i].ncells[0]].cno_nets++;
        cells[nets[i].ncells[1]].cno_nets++;
        *totsize += nets[i].nweight;
        if (nets[i].nweight > (*max_nweight)) {
            *max_nweight = nets[i].nweight;
        }
    }   /* for */

    /* set netlist pointers */
    *max_density = -1;
    *max_cweight = -1;
    *totcellsize = 0;
    int part_sum = 0;
    for (int i = 0; i < nocells; i++) {
        if (fscanf(fp, "%d", &cells[i].cweight) == EOF) {
            printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
            close_file(&fp);
            exit(1);
        }
        (*totcellsize) += cells[i].cweight;
        if (cells[i].cweight > (*max_cweight)) { 
            *max_cweight = cells[i].cweight;
        }
        if (cells[i].cno_nets > (*max_density)) {
            *max_density = cells[i].cno_nets;
        }
        cells[i].netlist = part_sum;
        part_sum += cells[i].cno_nets;
    }   /* for */

    close_file(&fp);

    /* create netlists */
    init_netlist(nonets, cells, nets, cnets);
}   /* read_graph */
Example #10
0
File: conduct.c Project: mwess/pcpc
int main(int argc, char** argv) {
  
  if( find_option( argc, argv, "-h" ) >= 0 )
  {
      printf( "Options:\n" );
      printf( "-h to see this help\n" );
      printf( "-n <int> to set the grid size\n" );
      printf( "-o <filename> to specify the output file name\n" );
      return 0;
  }
  
  int GRIDSIZE = read_int( argc, argv, "-n", DEFAULT_GRIDSIZE );
  // Check gridsize for some basic assumptions
  if(GRIDSIZE%2) {
    printf("Only even Gridsize allowed!\n");
    exit(1);
  }


  char *savename = read_string( argc, argv, "-o", "sample_conduct.txt" );
  FILE *f = savename ? fopen( savename, "w" ) : NULL;
  if( f == NULL )
  {
      printf( "failed to open %s\n", savename );
      return 1;
  }
  
  
  int t,i,j;
  double *T, *Tn;
  
  // Allocate Grid with a border on every side
  int padded_grid_size = GRIDSIZE+2;
  T=(double *) malloc((padded_grid_size)*(padded_grid_size)*sizeof(double));
  Tn=(double *) malloc((padded_grid_size)*(padded_grid_size)*sizeof(double));

  
  // remember -- our grid has a border around it!
  init_cells(T,padded_grid_size);
  
  
  for(t=0;t<TIMESTEPS;t++) { // Loop for the time steps
    
    for(i=1;i<GRIDSIZE+1;i++) {
      for(j=1;j<GRIDSIZE+1;j++) {
        
        Tn[i*padded_grid_size + j] = T[(i-1)*padded_grid_size + (j)] + T[(i+1)*padded_grid_size + (j)]
                                   + T[(i)*padded_grid_size + (j-1)] + T[(i)*padded_grid_size + (j+1)];
        Tn[i*padded_grid_size + j] /= 4;
      }
    }

    for(i=1;i<GRIDSIZE+1;i++) {
      for(j=1;j<GRIDSIZE+1;j++) {
        T[i*padded_grid_size + j] = Tn[i*padded_grid_size + j];
      }
    }
    
    if(!(t % PRINTSTEP)) {
      // print(T,padded_grid_size,t);
        save(f,T,padded_grid_size,t);
    }
    
  }
  
  fclose(f);
  
  return 0;
}