SciML / SciMLBook

Parallel Computing and Scientific Machine Learning (SciML): Methods and Applications (MIT 18.337J/6.338J)

Home Page:https://book.sciml.ai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible mistake in lecture 5 code

giacomoran opened this issue · comments

Hi,

I think there is a mistake in lecture 5 notes, in the "Multithreaded Parameter Searches" section, in the following code:

const _u_cache_threads = [Vector{typeof(@SVector([1.0,0.0,0.0]))}(undef,1000) for i in 1:Threads.nthreads()]
function compute_trajectory_mean5(u0,p)
  # u is automatically captured
  solve_system_save!(_u_cache_threads[Threads.threadid()],lorenz,u0,p,1000);
  mean(_u_cache)
end
@btime compute_trajectory_mean5(@SVector([1.0,0.0,0.0]),p)

After solving the system, the iteration are stored in _u_cache_threads[Threads.threadid()], but then the mean is computed on _u_cache, which, in my understanding, is not used anymore at this point of the notes.
It can be deceiving since serial_out - threaded_out it's still all 0s, but if you check the output of any of serial_out or threaded_out, the means for different ps have all the same value.

I think it should be mean(_u_cache_threads[Threads.threadid()]), is that correct?

(I'm not actually taking the course, I'm not a MIT student, I studying from the lecture notes in this repo)

Giacomo Randazzo

I think it should be mean(_u_cache_threads[Threads.threadid()]), is that correct?

Yes, it should be. Thanks for catching this. I'll have to find time to update this.