help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Help-gsl Digest, Vol 126, Issue 3


From: M A
Subject: Re: [Help-gsl] Help-gsl Digest, Vol 126, Issue 3
Date: Sun, 4 May 2014 19:35:08 +0100 (BST)

Ok, I think I got the idea.
I don't use c++11, however I think that the ansi c code attached works in the 
same sense.
I allocated memory for a number = omp_get_max_threads() of generators.

Thank you very much,

Al.


On Sunday, 4 May 2014, 17:00, "address@hidden" <address@hidden> wrote:
 
Send Help-gsl mailing list submissions to
    address@hidden

To subscribe or unsubscribe via the World Wide Web, visit
    https://lists.gnu.org/mailman/listinfo/help-gsl
or, via email, send a message with subject or body 'help' to
    address@hidden

You can reach the person managing the list at
    address@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Help-gsl digest..."


Today's Topics:

   1. Usage of GSL random in parallel code [OpenMP] (Altro)
   2. (no subject) (M A)
   3. Re: Usage of GSL random in parallel code [OpenMP]
      (Klaus Huthmacher)


----------------------------------------------------------------------

Message: 1
Date: Sat, 03 May 2014 21:32:49 +0100
From: Altro <address@hidden>
To: address@hidden
Subject: [Help-gsl] Usage of GSL random in parallel code [OpenMP]
Message-ID: <address@hidden>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear All

I wish to use effectively use the gsl random number generator jointly 
with OpenMP on a HPC cluster.

The simulation I have to do are quite simple: just let evolve an
"ensemble" of system with the same dynamics. Parallelize such a code 
with OpenMP "seems" straightforward.
As the GSL does not support parallel processing, I suppose that we must 
use a different random number generator for each element of the ensemble;
Indeed I don't know if this is a good procedure.

The ensemble could be very big and it would be simply impossible to 
allocate memory for all generators associated with the Systems of the 
ensemble.
Then my question is:
Is this still a correct way to use the GSL random generator on OpenMP?

An idea of how the allocation could be done is given in the code below.
Does it make any sense? If not, which is the correct way?

Best wishes,

Al.



#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <omp.h>

int main (){
     int i;

     int DIM_ENSEMBLE = 10000000000;

     double *d;
     gsl_rng **r ;

     d = malloc(DIM_ENSEMBLE*sizeof(double));
     r = malloc(DIM_ENSEMBLE*sizeof(gsl_rng*)) 
;                                            ;
     for (i=0;i<DIM_ENSEMBLE;i++){
         r[i] = gsl_rng_alloc (gsl_rng_mt19937);
//        r[i] = gsl_rng_alloc (gsl_rng_taus);
         gsl_rng_set(r[i],i);
     }


     size_t n = gsl_rng_size (r[0]);  //size in byte (the size of 
tausworthe is 24 ; the size of mersenne twister is 5000)

#pragma omp  parallel for default(none) shared(r,d) shared(DIM_ENSEMBLE)
     for  (i =0; i< DIM_ENSEMBLE; i++) {
         d[i] = gsl_rng_uniform(r[i]);
     }

#pragma omp  parallel for default(none) shared(d) shared(DIM_ENSEMBLE)
     for (i=0;i<DIM_ENSEMBLE;i++){
         printf("%d %f\n",i,d[i]);
     }

     printf("The size in Mb of the vector r is %lu 
Mb\n",n*DIM_ENSEMBLE/1000000);

     free(d);

    for (i=0;i<DIM_ENSEMBLE;i++){
         gsl_rng_free (r[i]);
    }
    free(r);

return 0;
}



------------------------------

Message: 2
Date: Sat, 3 May 2014 21:58:45 +0100 (BST)
From: M A <address@hidden>
To: "address@hidden" <address@hidden>
Subject: [Help-gsl] (no subject)
Message-ID:
    <address@hidden>
Content-Type: text/plain; charset=utf-8

Dear All I wish to use effectively use the gsl random number generator jointly 
with OpenMP on a HPC cluster. The simulation I have to do are quite simple: 
just let evolve an
"ensemble" of system with the same dynamics. Parallelize such a code 
with OpenMP "seems" straightforward.
As the GSL does not support parallel processing, I suppose that we must 
use a different random number generator for each element of the ensemble;
Indeed I don't know if this is a good procedure. The ensemble could be very big 
and it would be simply impossible to 
allocate memory for all generators associated with the Systems of the 
ensemble.
Then my question is:
Is this still a correct way to use the GSL random generator on OpenMP? An idea 
of how the allocation could be done is given in the code below.
Does it make any sense? If not, which is the correct way? Best wishes, Al. 
#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <omp.h> int main (){ int i; int DIM_ENSEMBLE = 10000000000; double *d; 
gsl_rng **r ; d = malloc(DIM_ENSEMBLE*sizeof(double)); r = 
malloc(DIM_ENSEMBLE*sizeof(gsl_rng*)) 
;                                            ; for (i=0;i<DIM_ENSEMBLE;i++){ 
r[i] = gsl_rng_alloc (gsl_rng_mt19937);
//        r[i] = gsl_rng_alloc (gsl_rng_taus); gsl_rng_set(r[i],i); } size_t n 
= gsl_rng_size (r[0]);  //size in byte (the size of 
tausworthe is 24 ; the size of mersenne twister is 5000) #pragma omp  parallel 
for default(none) shared(r,d) shared(DIM_ENSEMBLE) for  (i =0; i< DIM_ENSEMBLE; 
i++) { d[i] = gsl_rng_uniform(r[i]); } #pragma omp  parallel for default(none) 
shared(d) shared(DIM_ENSEMBLE) for (i=0;i<DIM_ENSEMBLE;i++){ printf("%d 
%f\n",i,d[i]); } printf("The size in Mb of the vector r is %lu 
Mb\n",n*DIM_ENSEMBLE/1000000); free(d); for (i=0;i<DIM_ENSEMBLE;i++){ 
gsl_rng_free (r[i]); } free(r); return 0;
} 

------------------------------

Message: 3
Date: Sun, 4 May 2014 15:14:14 +0200
From: "Klaus Huthmacher" <address@hidden>
To: "Altro" <address@hidden>
Cc: address@hidden
Subject: Re: [Help-gsl] Usage of GSL random in parallel code [OpenMP]
Message-ID:
    <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

Dear Altro,

I would simply use a wrapper around a C++ std::vector who holds as many
C++11 random number generators (engines) as you use threads in your code.
By calling a random number, the engine in the ith index of the vector is
used, where i is the thread id.

Please see the appended minimal example mb.cpp with the wrapper
rng-omp.{h,cpp}.

Best wishes and keep us informed,
-- Klaus.




> Dear All
>
> I wish to use effectively use the gsl random number generator jointly
> with OpenMP on a HPC cluster.
>
> The simulation I have to do are quite simple: just let evolve an
> "ensemble" of system with the same dynamics. Parallelize such a code
> with OpenMP "seems" straightforward.
> As the GSL does not support parallel processing, I suppose that we must
> use a different random number generator for each element of the ensemble;
> Indeed I don't know if this is a good procedure.
>
> The ensemble could be very big and it would be simply impossible to
> allocate memory for all generators associated with the Systems of the
> ensemble.
> Then my question is:
> Is this still a correct way to use the GSL random generator on OpenMP?
>
> An idea of how the allocation could be done is given in the code below.
> Does it make any sense? If not, which is the correct way?
>
> Best wishes,
>
> Al.
>
>
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <gsl/gsl_rng.h>
> #include <gsl/gsl_randist.h>
> #include <omp.h>
>
> int main (){
>      int i;
>
>      int DIM_ENSEMBLE = 10000000000;
>
>      double *d;
>      gsl_rng **r ;
>
>      d = malloc(DIM_ENSEMBLE*sizeof(double));
>      r = malloc(DIM_ENSEMBLE*sizeof(gsl_rng*))
> ;                                            ;
>      for (i=0;i<DIM_ENSEMBLE;i++){
>          r[i] = gsl_rng_alloc (gsl_rng_mt19937);
> //        r[i] = gsl_rng_alloc (gsl_rng_taus);
>          gsl_rng_set(r[i],i);
>      }
>
>
>      size_t n = gsl_rng_size (r[0]);  //size in byte (the size of
> tausworthe is 24 ; the size of mersenne twister is 5000)
>
> #pragma omp  parallel for default(none) shared(r,d) shared(DIM_ENSEMBLE)
>      for  (i =0; i< DIM_ENSEMBLE; i++) {
>          d[i] = gsl_rng_uniform(r[i]);
>      }
>
> #pragma omp  parallel for default(none) shared(d) shared(DIM_ENSEMBLE)
>      for (i=0;i<DIM_ENSEMBLE;i++){
>          printf("%d %f\n",i,d[i]);
>      }
>
>      printf("The size in Mb of the vector r is %lu
> Mb\n",n*DIM_ENSEMBLE/1000000);
>
>      free(d);
>
>     for (i=0;i<DIM_ENSEMBLE;i++){
>          gsl_rng_free (r[i]);
>     }
>     free(r);
>
> return 0;
> }
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mb.cpp
Type: text/x-c++src
Size: 389 bytes
Desc: not available
URL: 
<http://lists.gnu.org/archive/html/help-gsl/attachments/20140504/fa7f9d3d/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rng-omp.h
Type: text/x-chdr
Size: 472 bytes
Desc: not available
URL: 
<http://lists.gnu.org/archive/html/help-gsl/attachments/20140504/fa7f9d3d/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rng-omp.cpp
Type: text/x-c++src
Size: 392 bytes
Desc: not available
URL: 
<http://lists.gnu.org/archive/html/help-gsl/attachments/20140504/fa7f9d3d/attachment-0001.cpp>

------------------------------

_______________________________________________
Help-gsl mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-gsl


End of Help-gsl Digest, Vol 126, Issue 3
****************************************

Attachment: gsl-rng-parallel.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]