Software Archive
Read-only legacy content
17060 Discussions

aligning arrays on 64 byte boundaries for use on MIC

conor_p_
Beginner
555 Views

I have recently tried to export a code to a MIC, and obtained the seg fault error. I did some research, and believed it was because my arrays were not aligned properly. I currently have a code whose premise, IE an example since the real one is too long,is as shown below.My goal here is to always have the cl, loc_r, and cv variables aligned on 64 byte boundaries for use on a xeon phi coprocessor. However, I don't know how to get the allocate command to do this. It is my current understanding that the -align array64byte is not sufficent here, but I could be incorrect.  Also assuming all the vectors are aligned, where is the appropriate place in dosomecalc() to place the !dir$ vector alligned statement? I have read both the data alignment to assist vectorization document as well as the fortran array data and arguments and vectorization, however neither one seemed to handle my case. However I readily admit that I am a chemical engineering grad student and not a computer scientist, so I very well may just not have understood the documents. Any Help is greatly appreciated.


    module mymod

      implicit none
    
      type cell_data
         double precision, allocatable :: loc_r(:,:)
      end type cell_data
    
      type vlist
         integer :: cnum
         double precision :: minx,miny,minz
      end type vlist
    
      type list
         type(cell_data), allocatable :: cl(:)
         type(vlist), allocatable :: cv(:,:)
      end type list
    
      type(list) :: listvar
    
      contains
    
        subroutine alloc()
         
          if(conditon1.eq.true)then
             deallocate(listvar%cl)
             allocate(listvar%cl(0:new_size)

             deallocate(listvar%cv)
             allocate(listvar%cv(0:new_size)
             
             do i = 1,new_size
                allocate(listvar%cl(i)%loc_r(3,someothersize)
             enddo
    
          elseif(condition2.eq.true)then
             do i = 1,cur_size
                deallocate(listvar%cl(i)%loc_r)
                allocate(listvar%cl(i)%loc_r(3,somenewsize)
             enddo
    
          end if
    
        end subroutine alloc
             
    
      end module mymod
     
      !--- this is another module
      subroutine dosomecalc()
        use mymod
        implicit none
    
        !--- loop over all cells
        do i = 0,listvar%ncellT-1
    
           do k=1,26
        
              !---determine this cell
              cell_neigh = listvar%cv(k,i)%cnum
              
              if(cell_neigh.gt.i)then
    
                 !---minimum image
                 minx =listvar%cv(k,i)%min_x
                 miny =listvar%cv(k,i)%min_y
                 minz =listvar%cv(k,i)%min_z
    
    
                 !--- number of particles in cell i
                 cell1_num = listvar%cl(i)%num
           
                 !--- loop over particles in each cell
             
                 do j = 1, cell1_num
                                                
                    x1 = listvar%cl(i)%loc_r(1,j)
                    y1 = listvar%cl(i)%loc_r(2,j)
                    z1 = listvar%cl(i)%loc_r(3,j)
                                                                                               
                    !--- number of particles in cell_neigh  
                    cell2_num = listvar%cl(cell_neigh)%num
                                     
                    do l= 1, cell2_num
                                       
                       x2 = listvar%cl(cell_neigh)%loc_r(1,l)
                       y2 = listvar%cl(cell_neigh)%loc_r(2,l)
                       z2 = listvar%cl(cell_neigh)%loc_r(3,l)
                       
                       !--- obtain displacements
                       !--- apply minimum image here
                       dx = x2-x1-minx
                       dy = y2-y1-miny
                       dz = z2-z1-minz
                                
                       dr2 = dx*dx+dy*dy+dz*dz
                       if(dr2.lt.param%rcut2)then
                                            
                          dr2i  = 1.0d0/dr2
                          dr6i  = dr2i*dr2i*dr2i
                          dr12i = dr6i*dr6i
                          energy = energy + dr12i - dr6i                 
                       endif
                    enddo
                 enddo         
              endif
           enddo
        enddo
    
      end subroutine dosomecalc

 

0 Kudos
1 Reply
Kevin_D_Intel
Employee
555 Views

Duplicate post, refer to https://software.intel.com/en-us/forums/topic/516306 for comments.

0 Kudos
Reply