#include #include #include "allvars.h" #include "proto.h" //Revamped by NANDHANA SAKTHIVEL as part of her Master thesis, DSSC, UNITS, Italy void gridding() { if(global_rank == 0)printf("GRIDDING DATA\n"); // Create histograms and linked lists TAKE_TIME_START(init); // Initialize linked list initialize_array(); TAKE_TIME_STOP(init); TAKE_TIME_START(process); // Sector and Gridding data gridding_data(); TAKE_TIME_STOP(process); #ifdef USE_MPI MPI_Barrier(MPI_COMM_WORLD); #endif return; } void initialize_array() { histo_send = (long*) calloc(nsectors+1,sizeof(long)); int * boundary = (int*) calloc(metaData.Nmeasures,sizeof(int)); double vvh; for (long iphi = 0; iphi < metaData.Nmeasures; iphi++) { boundary[iphi] = -1; 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]++; 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 VERBOSE for (int iii=0; iii= 0 ) requests = (MPI_Request *)calloc( Me.Ntasks[WORLD], sizeof(MPI_Request) ); #ifdef RING if( Me.Rank[myHOST] == 0 ) { *((int*)win_ctrl_hostmaster_ptr+CTRL_BARRIER_END) = 0; *((int*)win_ctrl_hostmaster_ptr+CTRL_BARRIER_START) = 0; } *((int*)Me.win_ctrl.ptr + CTRL_FINAL_STATUS) = FINAL_FREE; *((int*)Me.win_ctrl.ptr + CTRL_FINAL_CONTRIB) = 0; *((int*)Me.win_ctrl.ptr + CTRL_SHMEM_STATUS) = -1; MPI_Barrier(*(Me.COMM[myHOST])); blocks.Nblocks = Me.Ntasks[myHOST]; blocks.Bstart = (int_t*)calloc( blocks.Nblocks, sizeof(int_t)); blocks.Bsize = (int_t*)calloc( blocks.Nblocks, sizeof(int_t)); int_t size = size_of_grid / blocks.Nblocks; int_t rem = size_of_grid % blocks.Nblocks; blocks.Bsize[0] = size + (rem > 0); blocks.Bstart[0] = 0; for(int b = 1; b < blocks.Nblocks; b++ ) { blocks.Bstart[b] = blocks.Bstart[b-1]+blocks.Bsize[b-1]; blocks.Bsize[b] = size + (b < rem); } #endif #ifdef BINOMIAL copy_win_ptrs( (void***)&swins, Me.swins, Me.Ntasks[Me.SHMEMl] ); copy_win_ptrs( (void***)&cwins, Me.scwins, Me.Ntasks[Me.SHMEMl] ); MPI_Barrier(MPI_COMM_WORLD); // printf("The no of task in shared memory %d, host %d\n", Me.Ntasks[Me.SHMEMl], Me.Ntasks[myHOST]); dsize_4 = (size_of_grid/4)*4; end_4 = (double*)Me.win.ptr + dsize_4; end_reduce = (double*)Me.win.ptr + size_of_grid; while( (1<< (++max_level) ) < Me.Ntasks[Me.SHMEMl] ); // printf("Max level %d my rank %d\n",max_level, global_rank); *(int*)Me.win_ctrl.ptr = DATA_FREE; *((int*)Me.win_ctrl.ptr+1) = FINAL_FREE; MPI_Barrier(*(Me.COMM[myHOST])); #endif #endif #ifndef USE_MPI file.pFile1 = fopen (out.outfile1,"w"); #endif // calculate the resolution in radians resolution = 1.0/MAX(abs(metaData.uvmin),abs(metaData.uvmax)); // calculate the resolution in arcsec double resolution_asec = (3600.0*180.0)/MAX(abs(metaData.uvmin),abs(metaData.uvmax))/PI; if( global_rank == 0 ) printf("RESOLUTION = %f rad, %f arcsec\n", resolution, resolution_asec); for (long isector = 0; isector < nsectors; isector++) { double twt, tpr; TAKE_TIME(twt, tpr); // define local destination sector //isector = (isector_count+rank)%size; // this line must be wrong! [LT] // allocate sector arrays long Nsec = histo_send[isector]; double *uus = (double*) malloc(Nsec*sizeof(double)); double *vvs = (double*) malloc(Nsec*sizeof(double)); double *wws = (double*) malloc(Nsec*sizeof(double)); long Nweightss = Nsec*metaData.polarisations; long Nvissec = Nweightss*metaData.freq_per_chan; float *weightss = (float*) malloc(Nweightss*sizeof(float)); float *visreals = (float*) malloc(Nvissec*sizeof(float)); float *visimgs = (float*) malloc(Nvissec*sizeof(float)); // select data for this sector long icount = 0; long ip = 0; long inu = 0; #warning shall we omp-ize this ? for(long iphi = histo_send[isector]-1; iphi>=0; iphi--) { long ilocal = sectorarray[isector][iphi]; uus[icount] = data.uu[ilocal]; vvs[icount] = data.vv[ilocal]-isector*shift; wws[icount] = data.ww[ilocal]; UNROLL(4) PRAGMA_IVDEP for (long ipol=0; ipol1e10 || visimgs[inu]<-1e10)printf("%f %f %ld %ld %d %ld %ld\n",visreals[inu],visimgs[inu],inu,Nvissec,rank,ilocal*metaData.polarisations*metaData.freq_per_chan+ifreq,metaData.Nvis); } icount++; } ADD_TIME(compose, twt, tpr); #ifndef USE_MPI double vvmin = 1e20; double uumax = -1e20; double vvmax = -1e20; #warning shall we omp-ize this ? for (long ipart=0; ipart= nsectors int target_rank = (int)(isector % size); #ifdef ONE_SIDE printf("One Side communication active\n"); #ifdef RING double _twt_; TAKE_TIMEwt(_twt_); int res = reduce_ring(target_rank); ADD_TIMEwt(reduce_ring, _twt_); #endif #ifdef BINOMIAL int res = reduce_binomial(target_rank); #endif #else // relates to #ifdef ONE_SIDE { double _twt_; TAKE_TIMEwt(_twt_); MPI_Reduce(gridss,grid,size_of_grid,MPI_DOUBLE,MPI_SUM,target_rank,MPI_COMM_WORLD); ADD_TIMEwt(mpi, _twt_); } #endif // closes #ifdef ONE_SIDE #endif // closes USE_MPI ADD_TIME(reduce, twt_r, tpr_r); // Deallocate all sector arrays free(uus); free(vvs); free(wws); free(weightss); free(visreals); free(visimgs); // End of loop over sector } #ifdef ONE_SIDE #ifdef RING for( int jj = 0; jj < size_of_grid; jj++) { *((double*)grid+jj) = *((double*)Me.fwin.ptr+jj); } #endif #endif free( histo_send ); #ifndef USE_MPI fclose(file.pFile1); #endif #ifdef USE_MPI // MPI_Win_fence(0,slabwin); #ifdef ONE_SIDE numa_shutdown(global_rank, 0, &MYMPI_COMM_WORLD, &Me); #endif MPI_Barrier(MPI_COMM_WORLD); #endif } void write_gridded_data() { #ifdef WRITE_DATA // Write results if (global_rank == 0) { printf("WRITING GRIDDED DATA\n"); file.pFilereal = fopen (out.outfile2,"wb"); file.pFileimg = fopen (out.outfile3,"wb"); #ifdef USE_MPI for (int isector=0; isector 1) { for (int iw=0; iw