multiply matrices using erlang and mnesia

Ulf Wiger (AL/EAB) <>
Fri Oct 21 09:42:54 CEST 2005


You could do it in a few different ways:

- Mnesia has an event mechanism. Each worker calls:

  mnesia:subscribe({table, Tab, simple}),

  and then receives messages of the following form:

  {mnesia_table_event, {write, NewRecord, ActivityId}}
  (the record tag is always set to the table name here)

- You can write a wrapper function that inserts the jobs
  in the table:

  Result = mnesia:activity(transaction, fun() ... end),
  tell_workers(Result, ...)

  Note that mnesia:activity() will EXIT upon abort, in
  case nothing got written.

- The 'rdbms' contrib has commit triggers. These will only
  fire if you actually use 'rdbms' as the activity module,
  though (this can be set as default in mnesia, but it 
  can also be over-ridden by the calling function.)

The subscribe function will of course always work. The 
other solutions can be bypassed by a rogue program.

/Uffe

> -----Original Message-----
> From: 
> [mailto:]On Behalf Of Chris Campbell
> Sent: den 21 oktober 2005 02:39
> To: 
> Subject: multiply matrices using erlang and mnesia
> 
> 
> Hi,
> 
> I'm playing with mnesia right now and am wondering the best way to
> solve this problem with it.  The idea is to multiply matrices by
> adding jobs of rows to complete to the database which workers will
> take on and complete, putting the resulting row back in the database
> for retrieval by the initiator.
> 
> Putting work up is easy.  The trick is to get work out to the workers
> (really, letting them know a job has arrived) and let the process that
> posted the work know it's done.  What's the best way to go about this
> using mnesia?  It has pattern matching, which allows picking the
> correct entries but I'm not sure how to let the workers know about the
> job short of polling the db periodically for new jobs.
> 
> The program is just a toy based on a lecture at uni on tuplespaces. 
> We went through an example use to multiply large matrices.  I want to
> adapt this to erlang and mnesia to see what it'd look like.
> 
> 
> 
> Regards,
> Chris
> 



More information about the erlang-questions mailing list