Re: a strange problem when openmp with glib ghash

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

 



On 22 September 2010 11:39, Qingpeng Niu <niuqingpeng@xxxxxxxxx> wrote:
> Hi, Lex
> Thank you for responding me second time.  I am touched. Sorry i forgot one
> line.
> They are not shared by each thread.
> There is a
> gh=pdt_a[i].gh;
> in the second parallel for.
> Therefore they are seperated. But  only add with g hash table it will stop
> there. If i comment the g hash table code in second loop, it will not stop.
> I think it should be some problem with glib.

omp parallel runs the whole block in a thread, ie each thread loops
through all the hashes, so they are shared.  Use omp for to make each
loop iteration a separate thread.

Cheers
Lex

> Qingpeng Niu
> On Tue, Sep 21, 2010 at 6:45 PM, Lex Trotman <elextr@xxxxxxxxx> wrote:
>>
>> On 22 September 2010 02:31, Qingpeng Niu <niuqingpeng@xxxxxxxxx> wrote:
>> > Hi,
>> >
>> > I do a parallel open mp for which used shared data of g_hash_table.
>> > Program
>> > do fine with the first parallel for loop but the third parallel for loop
>> > program will stop there and never be entered.
>> > g_thread_init(NULL);
>> > ..............
>> > #pragma omp parallel for private(i) shared(pdt_a)
>> >         for(i=0;i<psize;i++)
>> >          {
>> >                .............
>> >                 pdt_a[i].gh   = g_hash_table_new(g_str_hash,
>> > compare_strings);
>> >                ............
>> >          }
>> > #pragma omp parallel for private(i)
>> > shared(pdt_a,pit_a,lines,psize,nbuckets)
>> >         for(i=0;i<psize;i++)
>> >         {
>> >                for....
>> >                    lookup = g_hash_table_lookup(gh, input);
>> >               .....................
>> >                     g_hash_table_insert(gh, data, p_data);
>> >               .....................
>> >                       g_hash_table_replace(gh,strdup(input),p_data);
>> >         }
>> >
>>
>> It is not clear from this code if the hash tables are shared between
>> threads or if each thread has its own.
>>
>> If they are shared then you need to do the locking, from Gthread
>> documentation : "After calling g_thread_init(), GLib is completely
>> thread safe (all global data is automatically locked), but individual
>> data structure instances are not automatically locked for performance
>> reasons. So, for example you must coordinate accesses to the same
>> GHashTable from multiple threads."
>>
>> If they are not shared then this is a question for the openmp ML not
>> the glib ML.
>>
>> Cheers
>> Lex
>>
>>
>> > #pragma omp parallel for private(i)   // this parallel for will not be
>> > entered. Program will stop here and halt.
>> >         for(i=0;i<psize;i++)
>> > --
>> > Qingpeng Niu
>> > Department of Computer Science and Engineering at OSU
>> >
>> > _______________________________________________
>> > gtk-list mailing list
>> > gtk-list@xxxxxxxxx
>> > http://mail.gnome.org/mailman/listinfo/gtk-list
>> >
>> >
>> _______________________________________________
>> gtk-list mailing list
>> gtk-list@xxxxxxxxx
>> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>
>
> --
> Qingpeng Niu
> Department of Computer Science and Engineering at OSU
>
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list



[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux