From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Tue Jan 17 2012 - 17:17:25 CST

2012/1/17 Víctor <victor.gil.sepulveda_at_gmail.com>:
> I want to paralellize a rmsd matrix script... so it's a double loop where
> the inner loop works with its own data: an embarrasingly parallel problem
> (and I must add that it would be very difficult to run into a race condition
> in something like this :)  )

that has nothing to do with it. but since VMD's internals in general are
not thread safe, i.e. you must not access any VMD extensions to the
Tcl interpreter from multiple threads. if you just write something in plain
Tcl, then there are two cases to consider.

1) your calculation is not time very consuming:
  then the additional effort is a nice exercise, but doesn't
  result in much improvement anyway.

2) your calculation *is* time consuming:
  then a much better speedup would be achieved by replacing
  the Tcl script code with a C-code that is added to the Tcl
  interpreter as a plugin. since math in general in Tcl is *very*
  slow and simply porting it to C will give you much more speedup,
  than threading would do in Tcl. on top of that, you can multi-thread
  your plugin as much as you like, for as long as you only access
  the Tcl interpreter from one thread. i've done this a few times
  already using OpenMP directives.

that being said, for the reasons outline above, VMD already offers
some accelerated vector and matrix primitives programmed in C,
that you might want to use to speed up your Tcl code.
in particular, there are:

vecadd, vecsub, vecscale, transmult, vectrans, veclength,
vecmean, vecsum, transvec, transvecinv, transabout, vecstddev

cheers,
     axel.

>
> Thanks for your tips anyway!
>
>
> 2012/1/17 Ajasja Ljubetič <ajasja.ljubetic_at_gmail.com>
>>>
>>> As the script I'm coding works with my tcl interpreter (tclsh), What can
>>> I do to be able to use the thread extension within VMD's tcl interpreter?
>>
>>
>> Exactly what part would you like to parallelize? You could either invoke
>> the thread-enabled tclsh from vmd tcl (using exec or some such - but passing
>> data may be problematic) or run multiple instances of VMD (most probably in
>> text mode) from a bash or tcl script.
>>
>> Best regards,
>> Ajasja
>
>
>
>
> --
>
> Víctor Gil Sepúlveda
> E. Informatica - FIB - UPC

-- 
Dr. Axel Kohlmeyer
akohlmey_at_gmail.com  http://goo.gl/1wk0
College of Science and Technology
Temple University, Philadelphia PA, USA.