[mlpack-git] [mlpack/mlpack] parallel sgd (#603)
Stephen Tu
notifications at github.com
Thu Apr 7 13:48:23 EDT 2016
> + sumIterate.zeros();
> +
> +
> +
> + #pragma omp parallel shared(sumIterate,halt) private(it)
> + {
> + it=1;
> + while(it!=maxIterations && halt != true)
> + {
> + it++;
> +
> + int th_num=omp_get_thread_num(); //thread number is stored in which the thread is running.
> + arma::mat gradient(iterate.n_rows, iterate.n_cols); //To make gradient private to each thread it is declared here.
> + int selectedFunction;
> +
> + selectedFunction=std::rand()%numFunctions;
Calling `std::rand()` is problematic here. Either (a) it is not thread safe, in which case who knows how random these numbers will be, or (b) it is, and that will be a point of slowdown. Whether or not `std::rand()` is threadsafe is *implementation-specific* (see e.g. http://en.cppreference.com/w/cpp/numeric/random/rand). The easiest fix is to allocate seeds for each thread and use a thread local PRNG.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/603/files/a981f8322e84ec06a349b80d261639a282f4f7c5#r58914680
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160407/95249556/attachment.html>
More information about the mlpack-git
mailing list