C# and Java Operators Thread Safety
It seems these two step operations, i.e. x op= y, x++, x--, ++x, and --x, are NOT thread safe. It makes sense as these operations require reading the current value of the given variable and then updating it with the computed value. It is possible for threads to interleave between these operations resulting erroneous final values.
There are many ways to guarantee the atomicity in such cases including synchronized blocks, atomic data types such as Java AtomicInteger, and interlocked operations like in C#.
Here are some links that may help,
C# interlocked methods: http://msdn.microsoft.com/en-us/library/System.Threading.Interlocked_methods.aspx
Java atomic classes http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/package-summary.html
C# library to do threading similar to OpenMP like constructs http://msdn.microsoft.com/en-us/library/dd460717.aspx
A Java alternative OpenMP like parallel constructs https://wiki.rice.edu/confluence/display/HABANERO/Habanero+Multicore+Software+Research+Project
Weekend Carpentry: Shaver Holder
Nothing fancy, just a simple holder to keep my shaver in place. The hole is cut at an 30 degree angle. Initially I wanted to hide the tenon completely inside the mortise, but accidentally route the mortise all the way. Anyway, once fixed the joint is not visible.Running Chapel Programs on Titan
Last week I had the opportunity to use Titan, #2 supercomputer in the world as of June 2013, as part of the ATPESC program hosted by Argonne labs. Titan is a Cray XK7 machine and its user’s guide is available here.The following is a quick start to get Chapel programs run on multi-locale with Titan.
- Modules – the default set of modules is all what you need. You may load PrgEnv-cray/4.1.40 instead of the one loaded.
- Environment – you’ll need to have the following variables exported, usually through ~/.bashrc (in my case I used Chapel 1.7.0)
export CHPL_LOC=/tmp/work/csep65/chapel-1.7.0
export CHPL_HOME=$CHPL_LOC
export CHPL_COMM=gasnet
export GASNET_QUIET=yes
export CHPL_HOST_PLATFORM=cray-xk
export CHPL_LAUNCHER=pbs-aprun
export CHPL_LAUNCHER_QUEUE=batch
export CHPL_LAUNCHER_WALLTIME=00:10:00
export CHPL_LAUNCHER_ACCOUNT=TRN001
export CHPL_HOST_COMPILER=gnu
export PATH=${CHPL_LOC}/bin/$CHPL_HOST_PLATFORM:$PATH
Also, note the values in red need to be changed accordingly. The CHPL_LAUNCHER_ACCOUNT will be the account in Titan to get billed. You can find more information on this in the $CHPL_HOME/doc/platforms/README.cray (search for NCCS).
- Launcher tweak – note this fix is avaialble in Chapel code trunk following revision 21702 (http://sourceforge.net/p/chapel/code/21702/tree/trunk/) so will be necessary only if you are using a release 1.7.0 or older. A minor change to Chapel’s PBS launcher is necessary for these versions to work with Titan due to some upgrade in the qsub wrapper used by Titan. The fix is to change the two occurrences of –l size with –l nodes in $CHPL_HOME/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c
- Compile Chapel – once the above steps are completed use the Makefile under $CHPL_HOME to compile Chapel as usual
- Compile your program – use the chpl compiler to compile your program, which will create two outputs, for example a.out and a.out_real. More information on what each of this means is available in the $CHPL_HOME/doc/README.multilocale
- Start your program – you can use, for example ./a.out –nl 4 to launch your program on 4 locales. Chapel launcher will take care of submitting the correct PBS job for Titan’s job scheduler.
Tail Recursion with Python
Nice article on tail recursion with Python at http://web.mit.edu/kmill/www/programming/tailcall.htmlWeekend Carpentry: Wall Shelf
Well, it wasn't really a weekend project, but it could have been, hence the title.Update Aug 2014
Sketchup file at https://www.dropbox.com/s/0qa79linxceagwr/shelf.skp
PDF file at https://www.dropbox.com/s/5iaalnhmfmkkke8/Shelf.pdf
If you like to give it a try, here's the plan.
The top two are the vertical and horizontal center pieces. The last four pieces are for top, bottom, left, and right dividers. The joints are simply half lap joints (see http://jawoodworking.com/wp-content/uploads/2008/09/half-lap-joint.jpg).
Just remember to finish wood pieces before assembling. It's much easier than having to apply finish to the assembled product, which unfortunately is what I did.
How to Remove Shelf Liner Adhesive
Never ever use adhesive shelf liners, they suck!
Anyway, since you are here already, here are few tips to help you out.
1.) If you can, use a hairdryer to apply heat while pulling the liner.
2.) No matter how much caution you take, these will always leave a layer of sticky residue behind. This is where it sucks.
2.1) Use WD-40 (http://en.wikipedia.org/wiki/WD-40) and scrape off (using a plastic ruler edge or a small scraper) the sticky mess. You’ll have to do this multiple times and when you scrape use smooth single strokes rather going back and forth.
2.2.) Once you remove bulk of the goo, you’ll still end up having a sticky surface. This is where you need to use coconut oil. Apply oil to a piece of cloth and rub to remove the remaining left over adhesive.
3.) Once all this is done, it’s a good idea to wash away any remaining WD-40 and coconut oil with soapy water and wipe clean with a piece of cloth or sponge.
Excel Histograms
In case if you were looking to generate histograms in Excel http://support.microsoft.com/kb/214269C# String Vs Secure String
Interesting articles on the subject at,
1.) http://blogs.msdn.com/b/shawnfa/archive/2004/05/27/143254.aspx
In summary, a string object is not the best place to keep sensitive information such as passwords, credit card numbers, etc. due to its nature of not being able to lock in one place of memory, immutability (results multiple copies if modified), and possible page swaps (sensitive data now in tmp files) (see 1). Use SecureString as a solution, but sometimes you may still want to get the unsecured string representation as some APIs still don’t support secure strings (see 2).
While at it, you may also like to read about reading a string securely from console,
3.) http://msdn.microsoft.com/en-us/library/system.security.securestring.aspx
4.) http://stackoverflow.com/questions/3404421/password-masking-console-application
Running MPI.NET Applications with Mono in Ubuntu
Sometime back I played around Mono to get some of our parallel applications running on Ubuntu. These applications were C# based and used MPI.NET.The following blog post is a great starting point with all the details you'll need. So I'll skip the steps, except to point out couple of caveats you need to consider.
http://blog.biophysengr.net/2011/11/compiling-mpinet-under-ubuntu-oneiric.html
- automake versions above 1.9 will give you an error when building MPI.NET. May be you can change the make script to work with them, but I found it easy to just install automake1.9 to solve it.
- You'll need to add /usr/local/lib to your LD_LIBRARY_PATH. Essentially what you need to do is add this path to /etc/ld.so.conf and run ldconfig as root. See documenation from Mono on this at http://www.mono-project.com/DllNotFoundException
- Make sure to do chmod +x to your dlls
Repair Mr.Coffee (IDS77) Thermal Fuse
If you haven't bought this product yet, then STOP don't buy it!!If you, however, have bought it and broke it in the first run then continue.
Mine simply stopped working right on the day I bought it, in fact this is the second Mr. Coffee grinder I bought that day. May be I was trying to grind too much, but as a consumer device I'd expect it to "auto shut off" if it's too hot, rather burn itself.
The good news is, it only burns a thermal fuse, which is fairly easy to replace if you get under the hood. Once you remove the grinder cup you can see the following,
Homemade Meditation Benches
If you like to make one at home too, here are the details.
- Materials
- Wood – 1 x 8 (i.e. 3/4” x 7+1/4”) pine boards http://www.menards.com/main/building-materials/lumber-boards/boards/select-boards/1-x-8-x-8-select-pine-board/p-1934090-c-13118.htm
- Hinges – 3” x 3” door hinges, 1/4” round corner http://www.menards.com/main/tools-hardware/builders-hardware/door-window/residential-hinges/3x3-door-hinge/p-1475757-c-9687.htm
- Used 1/2” #10 Phillips flat head screws http://www.menards.com/main/building-materials/drywall/screws/wood/10-x-1-2-phillips-flat-wood-100pcs-pkg/p-1638963-c-8940.htm
- Leg sliders – Slipstick 3/4” Slider Foot http://www.amazon.com/Slipstick-CB190-4-Inch-Slider-16-Pack/dp/B000G9WK44/ref=sr_1_2?ie=UTF8&id=1365832735&sr=8-2&keywords=slipstick+slider
- Felt pads (not shown in picture) - http://www.amazon.com/Waxman-Self-Stick-Round-Brown-8-Inch/dp/B000VYN7CS/ref=sr_1_4?s=hi&ie=UTF8&qid=1365832847&sr=1-4&keywords=felt+pads
- De-waxed Shellac – Bulls Eye Seal Coat http://www.menards.com/main/interior-wood-care/specialty-wood-finishes/bulls-eye-seal-coat-universal-sealer/p-1963335-c-13129.htm
- Steps
- Cutting wood – a hand saw is enough actually, but I used a jig saw to make it bit faster and to cut the semi circles on legs. Dimensions are given below
- Fixing hinges – I used a router to make the mortises so that legs would close flush with the main board.You could omit this if this is not a concern.
- NOTE. I have flipped one side of the hinge (by removing its pin) to get them fixed as shown above. The reason was that the hinges I used won’t close flushed. See diagrams below.
- I didn’t like the protruding wedge shape (right most image above), hence the flipping (see here to know how to remove hinge pin) and mortising.
- Now, with some custom mortise routing I could get the legs to close flushed (above right). I made few jigs to make it easy to batch these as below.
- Finishing – 120 grit sanding followed by de-waxed shellac with 220 sanding between coats.
For legs, cut from the dashed lines, which are 1/2” from each edge. The 5.25 and 6.75 are lengths along the outside edges though. Alternatively, you could determine the angle from these two values and then calculate the the lengths for the actual cut piece. | The jig I made to draw semi circles and flush legs to the size. About the semi circle, I just used one of my wife’s planting pots to draw it. So I didn’t measure its diameter. You can use whatever shape or size you like. |
Mortise on the main board (ignore the writing), it’s the same for legs except the groove for hinge pin is on the edge rather in the middle and only half of the groove is necessary. | Simple jig made from 1/2” MDF. The dimensions for the hole depends on the flush trim router bit you are going to use. I used a 1/2” bit that came with this mortise kit. Roughly mine had about 1/16” added to actual hinge dimensions |
I had to use this 1/8” hardboard mask over the jig to get the depth difference in the mortise for groove and the hinge plate. So the process was to route entire shape WITH mask and then route the groove only WITHOUT mask. A plunge-based router would have eliminated this need. | Cross section of the mortise |
Notes on Windows PowerShell
- Is bit slow and creepy ;) but better than command line
- Running as administrator helps you overcome many of the access denied situations
- PowerShell script files are simple text files with .ps1 extension
- To run a script file,
- Open a PowerShell instance (preferably as administrator)
- Type the path to .ps1 file and hit enter
- If you get an error due to execution-policy is restricted, try
set-executionpolicy remotesigned
- The above will ask for your permission. To avoid that and force use
set-executionpolicy remotesigned -force
- If you want this to be done across a Windows HPC cluster using clusrun command
$nodes="node1,node2,..,noden" clusrun /nodes:$nodes powershell set-executionpolicy remotesigned -force
- To run a script file,
- To start a new process through a script - http://technet.microsoft.com/en-us/library/hh849848.aspx
start-process command "options and args"
- If you want it to be on the same window and wait for it to complete use
start-process command "options and args" -NoNewWindow –Wait
- If you want it to be on the same window and wait for it to complete use
- Invoke a command on a remote machine - http://technet.microsoft.com/en-us/library/hh849719.aspx
Invoke-Command -ComputerName $node -ScriptBlock {Start-Service MyService}
Handling variables
- Local variables
$x=10
$path="C:\users\dd"
$param0=$args[0] $param1=$args[1]
$javaBin=$env:JAVA_HOME + "\bin"
- A better alternative – number 2 indicates system variable. Use number 1 for user variable
$javaHome=[Environment]::GetEnvironmentVariable("JAVA_HOME",2)
[Environment]::SetEnvironmentVariable("Path","$tmp",2)
- String operations (few)
- Concatenation
$name="John" $x="hello " + $name + "! How are you ?"
$name.Substring(1) // "ohn" $name.Substring(1,2) // "oh"
$name.StartsWith("hello") // true
$name.IndexOf("ohn") // 1
$name.Length // 4
$javaHome=$env:JAVA_HOME // e.g. "C:\Program Files\Java\jdk1.7.0_10" $javaBinString=join-path -path $javaHome "bin" // e.g. "C:\Program Files\Java\jdk1.7.0_10\bin"
- For loop
for($i=1;$i -le 10; $i++) { //body }
- -le is <=
- -lt is <
- -gt is >
- -eq is == in usual programming language notation
- Foreach loop
$jars=ls ($env:TWISTER_HOME + "\lib") *.jar foreach ($jar in $jars) { $jar=$jar.DirectoryName + "\" + $jar.Name $cp=$jar+";"+$cp }
$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())This is pretty much I found useful for my work. Feel free to suggest any.
Study of Biological Sequence Structure: Clustering and Visualization
My presentation in our SALSA HPC weekly meeting.http://salsahpc.blogspot.com/2013/02/study-of-biological-sequence-structure.html
No comments :
Post a Comment