Skip to content
Mahrud Sayrafi edited this page Mar 12, 2021 · 1 revision

title: How-To permalink: wiki/How-To/ layout: wiki

Tuesday, January 11, 2010

How to run code in paralell! (by Dan and Bill)

  • difficult to handle, for example
    • if a global variable is changed inside the body of a function and different threads try to edit it. so two threads take the value of a global variable and change it and save it. Then the result of one of the htreads might get lost.
    • to be able to run it in paralell put in some new object local to the functions running in paralell
  • if applied in paralell to list, the entries should not be dependent upon each other
  • recursive functions will come later
  • it will be possible to spread different functions on the different cores
    • take the result of that which finishes first
    • there has to be an order on the different functions
  • the number of cores will be detected automatical
  • once that runs it should be also possible to paralellise your processes on multiple machines
  • A demo is coming up

Monday, January 10, 2010

hash tables, dot, underscore, sharp

x = new HashTable from {a => 4, 6 => a}

The most low level way to get items from the hash table is using #
x#a
x#6
x#7
x#?7
x_6 does return an error, but if working with a ring there is a high level operation that uses _ to return a generator. This is high level, so others are welcome implement using this.

On the other hand . is low level like # and the difference is that what ever comes to the right of . is NOT executed -- it takes the information as a symbol, where as with # what ever comes to the right of # is evaluated. For example,

x#a === x#(symbol a)

will always return true, where as x.a is not the same as x.(symbol a) since symbol a is not executed. The key is the execution.

For Packages: Tests vs. examples given in the documentation

All packages should have tests given using the function assert, example:

assert((2+2) === 4)

To see what asserts are in a package do

FirstPackage#"test values" etc.

In contrast, examples in the documentation should help users make use of the functions in the package. They should be illustrative and include text saying something about why that example is included.

You could also go to the web help and look at the source code.

seeing into functions

different methods for building sequences

x = {}; for i to 10 do x = append(x,i); x

This is o.k. for lists of length 5-10, but for 100 or 1000 it gets pretty bad --- with execution time increasing more than you would like --- it is an order n^2 algorithm.

There are three good ways (1-4) to avoid doing this --- and one (5) that isn't exceptional.

  1. Use a mutable list
    x = new MutableList; x#10000 = null; for i to 10000 do x#i = i;
    This makes a mutable list of size 10000 and then places the entries into the list.
  2. use the list command with for
    length for i to 10000 list i
  3. use a mutable hash table
    x = new MutableHashTable; for i to 10000 do x#i = i; length keys x
  4. use apply --- this has some reasonable garbage collection and reuse of memory, but is not quite as fast as list with for, for example
    apply(10000, i -> i+1)
  5. use a "lisp" approach --- This is not the fastest and as it gets larger you could overflow the stack the way this is being executed, so this is not ideal.
    x = (); for i to 10 do (x = (x,i);) length deepSplice x

lists vs. sequences

  • Sequences are designed to be fast for input to functions while lists are designed to be fast for applying functions to the list.

Some good commands for working with sequences and lists to remove nesting.

  • deepSplice
  • splice
  • flatten removes one

Thursday, January 7, 2010

You can get some information about using subversion at http://www.math.uiuc.edu/Macaulay2/Downloads/SourceCode/, the manual is at http://svnbook.red-bean.com/ (I find this quite helpful), and finally the subversion home page is http://subversion.tigris.org/

Here is a short tutorial of things you definitely need to know for this workshop.

To get started, you should create your account, so you have permission to change pages on the wiki.

Then at a command line, in a directory of your choice, type

svn co -q svn://macaulay2.math.uiuc.edu/Macaulay2/trunk/M2/Macaulay2/packages/development/msri2010

The command above will create a directory called msri2010. You should work on packages in this directory. All directions after this assume you are in the directory msri2010 (so make sure you change directories into msri2010 before proceeding). If the package you want to work on is not already in this directory, then you should add it by:

  • Place a copy of the package in this directory on your computer
  • type: svn add filename.m2
  • type: svn ci -m "adding filename.m2 to the directory"

The option -m "adding filename to the directory" leaves a message in the log to others about what you did. Replace the string in quotation marks my something appropriate.

If the package or file you want to work on is in the aim2009 directory, and you want to move it (and its entire history of changes) to this one, and you have write permission in the aim2009 directory (obtained by attending that workshop), then the following command can be used:

  • svn mv ../aim2009/filename.m2 .

Before working on a file you should always update the directory and the files in it using this command:

  • svn up

To check in changes, use the same command as above for checking in the add

  • svn ci -m "brief comment on the changes I made"

If you need more help than this (like you created a conflict and need to resolve it) then check out the manual!

Clone this wiki locally