读取Fortran中的大数据集

时间:2013-04-02 18:02:51

标签: fortran fortran90

我正在尝试将大数据文件读入Fortran,它包含大约40960000行,我稍后将其转换为矩阵,因此它将是6400 * 6400.当我使用更小的数据集尝试我的代码时,它工作正常。但是,当我使用更大的数据集时,它告诉我存在分段错误。我怀疑这是一个内存分配问题。有没有办法分配更多的内存或以其他方式纠正这个问题。

   program infectgrid
   implicit none

   integer ::  i,  individual, nedge,&
    tempinfect_tim_err, dumnum_infalpha0, dumnum_infalpha1, alpha0counter, &
    alpha1counter, obsrand,  minvalshift

    character (LEN = 50) :: parameterfilelabel,  parameterfile, networkfilelabel,        infectfilenamelabel, networkfile, infectfilename
             !allocatable to allow for reading in of individuals and time periods
   integer, dimension(:) , allocatable :: xcord, ycord, dummy3, recover_tim1, recover_tim2, &
     recover_tim3, recover_tim4, recover_tim5,  sampleadjshort, shortsamplecount, &
     cov1dum, covlog, covvect1uni

    character, dimension (:), allocatable :: rec
   integer, dimension (:, :) ,  allocatable :: link  
    real, dimension(:) , allocatable  :: alphavect

    call random_seed

 open(12, file = "filenamesinfection.txt", status = "old")

 read(12, *) parameterfile, networkfile, infectfilename
 close(12)

 open(12, file = parameterfile, status = "old")
 read(12, *)  individualname, alpha0name, alpha1name
 read(12, *) individual, alpha0, alpha1

  nedge = individual*individual

allocate(rec(1:nedge))
allocate(xcord(1:nedge))
allocate(ycord(1:nedge))
allocate(dummy3(1:nedge))
allocate(sampleadjshort(1:nedge))
allocate(shortsamplecount(1:nedge))
allocate(covlog(1:nedge))
allocate(cov1dum(1:nedge))


allocate(link(1:individual, 1:individual))


   link = 0
   covlog = 0

    print *, individual, alpha0, alpha1
    print *, link(individual, individual)

    print *, "test"
   open(10, file = networkfile, status = "old")
   print *, networkfile       
   print *, "test"
   do i = 1, nedge

   read ( 10, *) rec(i),  xcord(i), ycord(i), dummy3(i), cov1dum(i), sampleadjshort(i),      shortsamplecount(i)    

   if (dummy3(i) == 1)  then 

   link(xcord(i), ycord(i)) = 1
    end if

    if (xcord(i) == ycord(i)) then 
    covlog(i) = 1
    end if
    end do
    close(10)

    covvect1uni = pack(cov1dum, covlog == 1)

    print *, "xcord",  xcord(nedge), "ycord",  ycord(nedge)
    print *, link(individual, individual)
    print *, "test"

该文件打印出第一个和第二个“测试”,但不打印出链接语句,也不打印以“xcord”开头的行,不久之后给出了一个分段错误,即分段错误nohup ./swnetworkinfectrecoveralpha05covgeo2.out

关于编译器选项,我认为我正在使用大部分可用的东西:ifort -free -O2 -stand f03 -check bounds -traceback -warn all -fstack-protector -assume protect_parens -implicitnone -o swnetworkinfectrecoveralpha05covgeo2.out swnetworkinfectrecoveralpha05covgeo2.f90

0 个答案:

没有答案