Commit cfb257da authored by Nandhana Sakhtivel's avatar Nandhana Sakhtivel
Browse files

Changing the list data structure to array data structure

parent 4bddc68e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -23,10 +23,11 @@ double resolution, dx, dw, w_supporth;
clock_t start, end, start0, startk, endk;
struct timespec begin, finish, begin0, begink, finishk;

struct sectorlist ** sectorhead;
long * histo_send, size_of_grid;
double * grid, *gridss, *gridss_real, *gridss_img, *gridss_w;

#ifdef USE_MPI
    MPI_Win slabwin;
#endif

long **sectorarray;
+2 −5
Original line number Diff line number Diff line
@@ -112,11 +112,6 @@ extern struct fileData
        float * visimg;
}data;

extern struct sectorlist {
     long index;
     struct sectorlist * next;
}** sectorhead;


extern char filename[1000], buf[30], num_buf[30];
extern char datapath[900];
@@ -135,3 +130,5 @@ extern double * grid, *gridss, *gridss_real, *gridss_img, *gridss_w;
#ifdef USE_MPI
    extern  MPI_Win slabwin;
#endif

extern long **sectorarray;
+35 −52
Original line number Diff line number Diff line
@@ -2,12 +2,6 @@
#include "allvars.h"
#include "proto.h"

void Push(struct sectorlist** headRef, long data) {
     struct sectorlist* newNode = malloc(sizeof(struct sectorlist));
     newNode->index = data;
     newNode->next = *headRef;
     *headRef = newNode;
}

void gridding(){

@@ -19,7 +13,7 @@ void gridding(){
    start = clock();

    // Initialize linked list
    initialize_list();
    initialize_array();

    //Sector and Gridding data
    gridding_data();
@@ -37,16 +31,7 @@ void gridding(){

}

void initialize_list(){

    sectorhead = (struct sectorlist **) malloc((nsectors+1) * sizeof(struct sectorlist));
    for (int isec=0; isec<=nsectors; isec++)
    {
            sectorhead[isec] = malloc(sizeof(struct sectorlist));
            sectorhead[isec]->index = -1;
            sectorhead[isec]->next = NULL;
    }

void initialize_array(){

    histo_send = (long*) calloc(nsectors+1,sizeof(long));
    int * boundary = (int*) calloc(metaData.Nmeasures,sizeof(int));
@@ -54,29 +39,45 @@ void initialize_list(){
    for (long iphi = 0; iphi < metaData.Nmeasures; iphi++)
    {
     	   boundary[iphi] = -1;
           uuh = data.uu[iphi];
           vvh = data.vv[iphi];
           int binphi = (int)(vvh*nsectors);
           vvh = data.vv[iphi];  //less or equal to 0.6
           int binphi = (int)(vvh*nsectors); //has values expect 0 and nsectors-1. So we use updist and downdist condition
           // check if the point influence also neighboring slabs
           double updist = (double)((binphi+1)*yaxis)*dx - vvh;
           double downdist = vvh - (double)(binphi*yaxis)*dx;
           //
           histo_send[binphi]++;
           Push(&sectorhead[binphi],iphi);
           if(updist < w_supporth && updist >= 0.0) {histo_send[binphi+1]++; boundary[iphi] = binphi+1; Push(&sectorhead[binphi+1],iphi);};
              if(downdist < w_supporth && binphi > 0 && downdist >= 0.0) {histo_send[binphi-1]++; boundary[iphi] = binphi-1; Push(&sectorhead[binphi-1],iphi);};
           if(updist < w_supporth && updist >= 0.0) {histo_send[binphi+1]++; boundary[iphi] = binphi+1;};
           if(downdist < w_supporth && binphi > 0 && downdist >= 0.0) {histo_send[binphi-1]++; boundary[iphi] = binphi-1;};
    }

    sectorarray = (long**)malloc ((nsectors+1) * sizeof(long*));
    for(int sec=0; sec<(nsectors+1); sec++)
    {
      	   sectorarray[sec] = (long*)malloc(histo_send[sec]*sizeof(long));
    }

    long *counter = (long*) calloc(nsectors+1,sizeof(long));
    for (long iphi = 0; iphi < metaData.Nmeasures; iphi++)
    {
           vvh = data.vv[iphi];
           int binphi = (int)(vvh*nsectors);
           double updist = (double)((binphi+1)*yaxis)*dx - vvh;
           double downdist = vvh - (double)(binphi*yaxis)*dx;
           sectorarray[binphi][counter[binphi]] = iphi;
           counter[binphi]++;
           if(updist < w_supporth && updist >= 0.0) { sectorarray[binphi+1][counter[binphi+1]] = iphi; counter[binphi+1]++;};
           if(downdist < w_supporth && binphi > 0 && downdist >= 0.0) { sectorarray[binphi-1][counter[binphi-1]] = iphi; counter[binphi-1]++;};
    }
     
    
   #ifdef PIPPO
        struct sectorlist * current;
        long iiii = 0;
        for (int j=0; j<nsectors; j++)
        {
                current = sectorhead[j];
                iiii = 0;
                while (current->index != -1)
                for(long iphi = histo_send[j]-1; iphi>=0; iphi--)
                {
                        printf("%d %d %ld %ld %ld\n",rank,j,iiii,histo_send[j],current->index);
                        current = current->next;
                      printf("%d %d %ld %ld %ld\n",rank,j,iiii,histo_send[j],sectorarray[j][iphi]);
                      iiii++;
                }
        }
@@ -89,21 +90,6 @@ void initialize_list(){

void gridding_data(){

    // Create sector grid

    size_of_grid = 2*param.num_w_planes*xaxis*yaxis;
    gridss = (double*) calloc(size_of_grid,sizeof(double));
    gridss_w = (double*) calloc(size_of_grid,sizeof(double));
    gridss_real = (double*) calloc(size_of_grid/2,sizeof(double));
    gridss_img = (double*) calloc(size_of_grid/2,sizeof(double));
  
    // Create destination slab
    grid = (double*) calloc(size_of_grid,sizeof(double));
  
    // Create temporary global grid
    #ifndef USE_MPI
        double * gridtot = (double*) calloc(2*grid_size_x*grid_size_y*num_w_planes,sizeof(double));
    #endif
    double shift = (double)(dx*yaxis);
    
    // Open the MPI Memory Window for the slab
@@ -152,12 +138,10 @@ void gridding_data(){
        long icount = 0;
        long ip = 0;
        long inu = 0;
        struct sectorlist * current;
        current = sectorhead[isector];

         while (current->index != -1)
        for(long iphi = histo_send[isector]-1; iphi>=0; iphi--)
        {
              long ilocal = current->index;
              long ilocal = sectorarray[isector][iphi];
              //double vvh = data.vv[ilocal];
              //int binphi = (int)(vvh*nsectors);
              //if (binphi == isector || boundary[ilocal] == isector) {
@@ -177,7 +161,6 @@ void gridding_data(){
                     inu++;
		}
              icount++;
              current = current->next;
         }

         clock_gettime(CLOCK_MONOTONIC, &finishk);
+17 −0
Original line number Diff line number Diff line
@@ -348,6 +348,23 @@ void allocate_memory() {
     data.visreal = (float*) calloc(metaData.Nvis,sizeof(float));
     data.visimg = (float*) calloc(metaData.Nvis,sizeof(float));


     // Create sector grid
     
     size_of_grid = 2*param.num_w_planes*xaxis*yaxis;
     gridss = (double*) calloc(size_of_grid,sizeof(double));
     gridss_w = (double*) calloc(size_of_grid,sizeof(double));
     gridss_real = (double*) calloc(size_of_grid/2,sizeof(double));
     gridss_img = (double*) calloc(size_of_grid/2,sizeof(double));
     
     // Create destination slab
      grid = (double*) calloc(size_of_grid,sizeof(double));
     
     // Create temporary global grid
     #ifndef USE_MPI
     	   double * gridtot = (double*) calloc(2*grid_size_x*grid_size_y*num_w_planes,sizeof(double));
     #endif

}

void readData() {
+1 −2
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@ void readData();
/*  gridding.c */

void gridding();
void Push(struct sectorlist** headRef, long data);
void initialize_list();
void initialize_array();
void gridding_data();
void write_grided_data();