bidesh23

Untitled

Nov 14th, 2021 (edited)
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hi!
  2.  
  3. I received a code from github (https://github.com/exafmm/exafmm-alpha). I wish to incorporate the part of the code in our in-house fortran code.
  4.  
  5. The code from github is:
  6.  
  7.     program main
  8.       implicit none
  9.       integer i,ni,nj,images
  10.       integer,dimension (128) :: iseed
  11.       real(8) diff,norm
  12.       real(8),parameter :: pi=3.14159265358979312d0
  13.       real(8),allocatable,dimension(:) :: xi,ui,ud,xj,gj
  14.       ni = 1000 !10000
  15.       nj = 1000 !500000
  16.       allocate( xi(3*ni),ui(3*ni),ud(3*ni),xj(3*nj),gj(3*nj) )
  17.       do i = 1,128
  18.          iseed(i) = 0
  19.       enddo
  20.       call random_seed(put=iseed)
  21.       call random_number(xi)
  22.       call random_number(xj)
  23.       call random_number(gj)
  24.       do i = 1,nj
  25.          xj(3*i-2) = 5*(xj(3*i-2) - 0.5) * pi
  26.          xj(3*i-1) = 5*(xj(3*i-1) - 0.5) * pi
  27.          xj(3*i-0) = 5*(xj(3*i-0) - 0.5) * pi
  28.          gj(3*i-2) = (gj(3*i-2) - 0.5) / ni
  29.          gj(3*i-1) = (gj(3*i-1) - 0.5) / ni
  30.          gj(3*i-0) = (gj(3*i-0) - 0.5) / ni
  31.       enddo
  32.       do i = 1,ni
  33.          xi(3*i-2) = 3*(xi(3*i-2) - 0.5) * pi
  34.          xi(3*i-1) = 3*(xi(3*i-1) - 0.5) * pi
  35.          xi(3*i-0) = 3*(xi(3*i-0) - 0.5) * pi
  36.          ui(3*i-2) = 0
  37.          ui(3*i-1) = 0
  38.          ui(3*i-0) = 0
  39.       enddo
  40.       images = 0
  41.       call fmm_init(images)
  42.       call fmm_biot_savart(ni,xi,ui,nj,xj,gj)
  43.       call fmm_finalize()
  44.       deallocate( xi,ui,ud,xj,gj )
  45.     end program main
  46. And the make file for this is:
  47.  
  48.     include ../Makefile.include
  49.     lib_serial_ij: serial_wrapper_ij.o $(OBJECT)
  50.         ar -cr libfmm.a serial_wrapper_ij.o $(OBJECT)
  51.         ranlib libfmm.a
  52.    
  53.     test_serial_ij: test_serial_ij.o
  54.         make lib_serial_ij
  55.         $(FC) $? -L. -lfmm $(LFLAGS)
  56.         ./a.out
  57.  
  58. And Makefile.include is:
  59.  
  60.     .SUFFIXES: .cxx .cu .f90 .o
  61.     .PHONY: docs
  62.    
  63.     CUDA_INSTALL_PATH = /usr/local/cuda
  64.    
  65.     DEVICE  = cpu
  66.     #~ DEVICE  = gpu
  67.    
  68.     CXX     = mpicxx -g -O3 -lstdc++ -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include
  69.     NVCC    = nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include
  70.     FC      = mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include
  71.     FCC      = mpif90 -c -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include
  72.     LFLAGS  = -D$(DEVICE) -lstdc++ -ldl -lm
  73.     LFLAGS  += -lmpi_cxx
  74.     LFLAGS  += -lpthread
  75.    
  76.     ifeq ($(DEVICE),gpu)
  77.     LFLAGS  += -lcudart
  78.     endif
  79.     OBJECT  = ../kernel/$(DEVICE)Laplace.o ../kernel/$(DEVICE)BiotSavart.o\
  80.         ../kernel/$(DEVICE)Stretching.o ../kernel/$(DEVICE)Gaussian.o\
  81.         ../kernel/$(DEVICE)CoulombVdW.o
  82.    
  83.     .cxx.o:
  84.         $(CXX) -c $? -o $@ $(LFLAGS)
  85.     .cu.o:
  86.         $(NVCC) -c $? -o $@ $(LFLAGS)
  87.     .f90.o:
  88.         $(FC) -c $? -o $@
  89.  
  90. Now I wish to change the code a bit, instead of the main program I wish it as subroutine so that I can call it in our in-house code. The name of the subroutine is FMM_ij looks like:
  91.  
  92.     subroutine FMM_ij (n_s,n_t,v_x,v_y,v_z,xi,ui,xj,gj)
  93.     !###########################!
  94.     integer, intent (in) :: n_s, n_t
  95.     real*8, intent (out) :: v_x(n_t)
  96.     real*8, intent (out) :: v_y(n_t)
  97.     real*8, intent (out) :: v_z(n_t)
  98.     real*8, intent (in) :: xi(3*n_t)
  99.     real*8, intent (in) :: ui(3*n_t)
  100.     real*8, intent (in) :: xj(3*n_s)
  101.     real*8, intent (in) :: gj(3*n_s)
  102.     !###########################!
  103.     integer i,images
  104.     real(8),parameter :: pi=3.14159265358979312d0
  105.     !###########################!
  106.    
  107.     images = 0
  108.     print*, n_t,n_s,size(xi),size(ui),size(xj),size(gj)
  109.     print*, xi(500),ui(500),xj(500),gj(500)
  110.     call fmm_init(images)
  111.     call fmm_biot_savart(n_t,xi,ui,n_s,xj,gj)
  112.    
  113.     do i = 1,n_t
  114.         v_x(i) = ui(3*i-2)
  115.         v_y(i) = ui(3*i-1)
  116.         v_z(i) = ui(3*i-0)
  117.     enddo
  118.    
  119.     call fmm_finalize()
  120.     end subroutine FMM_ij
  121. What changes I should do in Makefile so that I get an object file of the subroutine FMM_ij and can call this subroutine in any other program?
  122. Thanks a lot.
Add Comment
Please, Sign In to add comment