Julia: fast file write on the fly

I encode a solver that must write several numbers to a file at each time step. The time step should be small, so I need to write the output often.

This figure shows code profiling . As you can see, the selected I / O area takes up a significant portion of the execution time.

IO runs as

println(out_file, t, " ", v.P[1], " ", v.P[end])

where I want to save the first and last element of the vector Pinside the data structure v, as well as the value t.

From profiling, it seems that most of the computational time is occupied by a function string.jl(which is not defined by me).

This makes you wonder if there is a more efficient way to write iterative output to a file.

Any suggestion?

thank

Additional Information

. , , -

out_file = open("file.out", "w")

delta_t = computeDeltaT()
t = 0
while t<T
  P = computeP()

  println(out_file, t, " ", P[1], " ", P[end])

  delta_t = computeDeltaT()
  t += delta_t
end

close(out_file)

, , , delta_t. P. , , , 5.

@isebarn 100 . -, .

+4
1

, , / ? , .

f = open(outfile,"w") # do this once
for i in someloop
    # do something
    write(f, "whatever") # write to stream but not flushed to disk
end
close(f) # now everything is flushed to the disk (i.e. now outfile will have changed)

, / (, , println, ), / N , ?

Edit: : http://docs.julialang.org/en/release-0.4/manual/networking-and-streams/

@isebarn, hdf5 . , .

, IO . , , P, , ?

+2

Source: https://habr.com/ru/post/1653149/


All Articles