srun --ntasks=32 --ntasks-per-node=16 --time=00:30:00 --partition=express --pty bash
Monday, February 29, 2016
Running interactive job with SLURM
Tuesday, December 15, 2015
Profiling Code on Mac
- With the gnu compile suite, compile your code with the -g flag (this isn't necessary but provides a better profiling experience and you get timing down to individual lines of code)
- Open Instruments
- Select Time Profiler

- At the top by the red circle and pause button, select Choose target and select your code. Provide a working directory and inputs as desired/needed.

- Click the red circle to begin profiling.
- At the bottom you should see the Call Tree filing up
- Double click on any item in the Call Tree to get more information

Wednesday, May 7, 2014
Compiling VisIt on Cluster
./build_visit2_12_3 --hdf5 --szip --silo --parallel --qt5 --console --prefix /home/msu/mowkes/opt/visit2_7_2 The build_visit script is available from https://wci.llnl.gov/codes/visit/source.html. Additional options are provided by running ./build_visit -h or visiting http://www.visitusers.org/index.php?title=Build_visit_overview
Monday, December 30, 2013
Improving workflow: Zotero & Latex
I use Zotero as my reference manager. I've tried others including the popular Mendeley program but find Zotero's import feature the easiest to use and Zotero meets my needs well.
There are a couple of add-ons that I recently added to Zotero to improve my workflow when adding and using references in Latex documents. The first keeps the bibtex file automatically updated whenever changes are made to your Zotero library. To do this install Zotero automatic export from rokdd.de/permanent:zotero-autoexporting
The second allows for cite-keys (e.g. \cite{smith_fluids_1987}) to be either copied and pasted or dragged and dropped directly into your favorite text editor. To do this I followed directions from this forum by Kramer. The add-on works by adding an additional export format to Zotero.
Copy the code from http://pastebin.com/GXmCJevn and save it in a file called BibtexCiteKeyOnly.js within the translators folder in your zotero. If you don't know where your zotero folder is you can find it by going to Zotero Preferences, Advanced, and clicking on Show Data Directory. Once you restart Zotero (or Firefox) enable the export mode by going to Zotero Preferences, Export, and choosing BibTeX-CITEP. You should now be able to drag a reference (or multiple references) into your text editor and get the citekey. Or you can copy the citekey using Cmd+Shift+C and paste it using Cmd+V.
Thursday, April 11, 2013
Start iPython notebook with inline plotting
ipython notebook --pylab inline
Friday, April 5, 2013
Mount filesystem using ssh
mkdir mountpoint
sshfs -o follow_symlinks hostname: mountpoint/
where hostname is what you use to ssh into the remote computer (e.g. name@computer.gov)
Saturday, March 30, 2013
Compliing and using LLNL Silo on Mac OS X and linking Fortran program
./configure --prefix=/opt/hdf5
make
make install
Download szip, uncompress and then install using
./configure --prefix=/opt/szip
make
make install
Download (silo), uncompress, then install using
./configure --enable-fortran --with-hdf5=/opt/hdf5/include/,/opt/hdf5/lib --with-szlib=/opt/szip/ --prefix=/opt/silo/ --disable-silex
make
make install
You should find the silo libraries in /opt/silo/lib. To make sure you have the fortran routines you can run in /opt/silo/lib
nm libsiloh5.a | grep dbcreate
which should show
00000000000039f0 T _dbcreate_ <==== this shows you have the fortran routines
0000000000019078 S _dbcreate_.eh
To compile a program that uses silo.h run a command similar to
gfortran -I /opt/silo/include/ -L /opt/silo/lib/ -L /opt/hdf5/lib/ -L /opt/szip/lib/ -o fbasic fbasic.f -lsiloh5 -lhdf5 -lsz -lz -lstdc++
that compiles fbasic.f, which is an example program provided by LLNL (see below)
fbasic.f
c-----------------------------------------------------------------------------
c
c Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
c Produced at the Lawrence Livermore National Laboratory
c LLNL-CODE-400142
c All rights reserved.
c
c This file is part of VisIt. For details, see https://visit.llnl.gov/. The
c full copyright notice is contained in the file COPYRIGHT located at the root
c of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
c
c Redistribution and use in source and binary forms, with or without
c modification, are permitted provided that the following conditions are met:
c
c - Redistributions of source code must retain the above copyright notice,
c this list of conditions and the disclaimer below.
c - Redistributions in binary form must reproduce the above copyright notice,
c this list of conditions and the disclaimer (as noted below) in the
c documentation and/or other materials provided with the distribution.
c - Neither the name of the LLNS/LLNL nor the names of its contributors may
c be used to endorse or promote products derived from this software without
c specific prior written permission.
c
c THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
c AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
c LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
c DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
c SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
c CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
c DAMAGE.
c
c-----------------------------------------------------------------------------
program main
implicit none
include "silo.inc"
integer dbfile, ierr
c The 11 and 22 arguments represent the lengths of strings
ierr = dbcreate("fbasic.silo", 11, DB_CLOBBER, DB_LOCAL,
. "Comment about the data", 22, DB_HDF5, dbfile)
if(dbfile.eq.-1) then
write (6,*) 'Could not create Silo file!\n'
goto 10000
endif
c Add other Silo calls here.
c Close the Silo file.
ierr = dbclose(dbfile)
10000 stop
end
Monday, March 18, 2013
Remove URL and DOI from Latex/Bibtex references when using Zotero
~/Library/Application\ Support/Firefox/Profiles/uawt2ewt.default/zotero/translators/BibTeX.js
Around line 2225 you need to change the code from
for(var field in fieldMap) {
if(item[fieldMap[field]]) {
writeField(field, item[fieldMap[field]]);
}
}
to
for(var field in fieldMap) {
if (field == "url") continue; // Added to remove url
if (field == "doi") continue; // Added to remove doi
if(item[fieldMap[field]]) {
writeField(field, item[fieldMap[field]]);
}
}
Now when you export your .bib files the url and doi fields will be ignored.
Monday, October 29, 2012
Bash one-liner: Sort files by scientific number in the filename
ls data_* | sed -e 's/data_//g' | sort -g | sed -e 's/^/data_/g'
Friday, April 27, 2012
Script a script and pass inputs
Ok here it goes. Imagine you have a script called repeater that takes a user input and gives it back (not very useful but easy to test with).
Here is my script.
#!/bin/bash
# Repeater
echo "Enter something for me to repeat"
read -e text
echo "You said: $text"
If you call the script, it prompts you for an input and then repeats what you said. For example
>>./repeater
Enter something for me to repeat
apple
You said: apple
Now here is the interesting part. We're going to call the script and provide the input, all with one command.
>> ./repeater << EOF
> apple
> EOF
If you want to put this in a script it could look like this
#!/bin/bash
./repeater << EOF
apple
EOF
./repeater << EOF
bannana
EOF
./repeater << EOF
kiwi
EOF
If your script requires multiple user inputs, put them on different lines, e.g.,
>> ./repeater_multiInputs << EOF
> input 1
> input 2
> input 3
> EOF
Friday, March 9, 2012
Check for a slow processor on a cluster
The code is below and basically times how long it takes to do a bunch of useless work on each processor. I then sorts the times and prints the fastest and slowest results so you can compare. Finally it tells you which node the slowest processor is on.
FYI, a node is basically a small computer that is part of the cluster. On the node are usually multiple processors.
Ok, here is the code:
PROGRAM main
use mpi
implicit none
!include 'mpif.h'
integer :: ierr, n, i, myrank, nproc, temp_i, minIndex, slowest
real*8 :: x, start_time, end_time, temp_r, mytime
real*8, dimension(:), allocatable :: time
integer, dimension(:), allocatable :: rank
character(len=MPI_MAX_PROCESSOR_NAME) :: myname
! Initialize MPI environment
call MPI_INIT(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)
call MPI_GET_PROCESSOR_NAME(myname,n,ierr)
if (myrank.eq.0) print *,'Starting test'
if (myrank.eq.0) print *,' results accurate to ',MPI_WTICK()
allocate( time(nproc)); time=real(0,8)
allocate( rank(nproc));
do n = 1, 10
! Start timing
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
start_time = MPI_Wtime()
! Do a bunch of useless work
x=real(0,8)
do i = 1, 100000000
if (mod(i,2)>0) then
x = x + real(i,8)
else
x = x - real(i,8)
end if
end do
! Stop timing
end_time = MPI_Wtime()
! Collect times
mytime = end_time - start_time
call MPI_GATHER(mytime,1,MPI_REAL8, &
time,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
! Find slowest processors
if (myrank.eq.0) then
! Form rank array
do i = 1, nproc
rank(i)=i-1
end do
! Selection sort
do i = 1, nproc-1
minIndex = minloc(time(i:), 1) + i - 1
if (time(i) > time(minIndex)) then
temp_r = time(i)
temp_i = rank(i)
time(i) = time(minIndex)
rank(i) = rank(minIndex)
time(minIndex) = temp_r
rank(minIndex) = temp_i
end if
end do
! Print fastest 5 and slowest 5 processors rank and time
print *,''
write(*,'(A,5I10.1,A,5I10.1)') &
'Rank (fastest-slowest)',rank(1:5),' ...',rank(nproc-4:nproc)
write(*,'(A,5F10.6,A,5F10.6)') &
'Time (fastest-slowest)',time(1:5),' ...',time(nproc-4:nproc)
end if
! Print name of slowest processor
slowest=rank(nproc)
call MPI_BCAST(slowest,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
if (myrank.eq.slowest) print *, &
'The slowest processor is on ',trim(myname)
end do
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
if (myrank.eq.0) print *,'Test complete'
! Close parallel environment
call MPI_FINALIZE(ierr)
END PROGRAM main
Save the code to node-test.f90. Compile the code using a command like "mpif90 -o node-test node-test.f90" and then run the code on your cluster using your usual approach.
The output shows the 5 fastest and 5 slowest processor ranks and the time it took each of them to complete the test. The test is repeated 10 time to see if one processor is consistently the slowest.
If you use the code and find issues or improvements please post a comment below.
Wednesday, January 25, 2012
High quality LaTeX figures using gnuplot - take 2
Step 1: Create the image files using gnuplot
>> gnuplot
gnuplot>> set term epslatex
gnuplot>> set output "test_figure.tex"
gnuplot>> set xlabel '$\lambda_\theta$'
gnuplot>> set ylabel '$\omega - \mathrm{pi}$'
gnuplot>> set title 'This is a test'
gnuplot>> p sin(x) t 'sin(x)', cos(x) t 'cos(x)'
gnuplot>> exit
>>
Which should have made two files: test_figure.tex and test_figure.eps
Step 2: Compile figure in LaTeX document
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\input{test_figure.tex}
\end{figure}
\end{document}
This code can be compiled using pdflatex and will produce the following figure:
LaTeX circuit diagrams
\documentclass{article}
\usepackage[free-standing-units]{siunitx}
\usepackage[american]{circuitikz}
\usepackage{tikz}
\begin{document}
\begin{figure}[h!]
\centering
\begin{circuitikz} \draw
(0,0) to[V, l=$9V$](0,4)
(0,4) -- (4,4)
(4,4) to[R, l=$R>470\ohm$] (4,2)
(4,2) to[led, l=LED](4,0)
(4,0) -- (0,0)
;
\end{circuitikz}
\caption{Base circuit}\label{fig:circuit1}
\end{figure}
\end{document}
The manual with complete list of symbols can be downloaded from
http://tug.org/texlive/devsrc/Master/texmf-dist/doc/latex/circuitikz/circuitikzmanual.pdf
Thursday, January 19, 2012
Gnuplot - create high quality plot for publication
#!/bin/bash
# Output file.pdf
file=trig
gnuplot << TOEND
# Setup output
set term postscript eps enhanced \
dashlength 4 \
linewidth 5 \
"Helvectica" 24\
color
set output "$file.eps"
#unset key
set yrange [-1.1:1.1]
set xlabel 'x'
set ylabel 'y'
# Format plot
p sin(x) t 'sin(x)'\
, cos(x) t 'cos(x)'
TOEND
epstopdf $file.eps
rm $file.eps
Make the code executable by running
chmod +x plot-gnu
Run the code with
./plot-gnu
You should now have a high quality plot in a file called trig.pdf
A useful plot that shows all of the available (black and white) linetypes can be created with the following code. Follow the same steps as above. This code makes a file call linetypes.pdf.
#!/bin/bash
# Output file.pdf
file=linetypes
gnuplot << TOEND
# Setup output
set term postscript eps enhanced \
dashlength 4 \
linewidth 5 \
"Helvectica" 24\
#color
set output "$file.eps"
unset key
set yrange [0:10]
set xlabel 'x'
set ylabel 'Linetype'
# Format plot
p 1 lt 1\
, 2 lt 2\
, 3 lt 3\
, 4 lt 4\
, 5 lt 5\
, 6 lt 6\
, 7 lt 7\
, 8 lt 8\
, 9 lt 9
TOEND
epstopdf $file.eps
rm $file.eps
Wednesday, December 14, 2011
make[3]: m2c: Command not found
Wednesday, September 21, 2011
Making custom theme for LaTeX
Created *.sty file that describes the theme. Here's mine.
\ProvidesPackage{beamerthemeCTF}
[2008/11/09 v1.0 beamer 'CTF' theme]
\mode
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{CTFLab.pdf}}
\setbeamertemplate{footline}{\vspace{1.2cm}}
\setbeamerfont{author}{size=\large}
\setbeamerfont{date}{size=\large}
\setbeamerfont{example text}{series=\bfseries}
\setbeamerfont{frametitle}{series=\bfseries,size=\large}
\setbeamerfont{framesubtitle}{series=\mdseries,size=\large}
\setbeamerfont{section}{series=\bfseries}
\setbeamerfont{title}{series=\bfseries}
\definecolor{CTFgrey}{RGB}{66,66,66}
\definecolor{CTFlightgrey}{RGB}{175,175,175}
\definecolor{CTFalmostwhite}{RGB}{225,225,225}
\definecolor{CTFred}{RGB}{180,28,27}
\definecolor{CTFtrans}{RGB}{0,0,0}
\setbeamercolor{alerted text}{fg=blue}
\setbeamercolor{block body alerted}{bg=red}
\setbeamercolor{block body}{bg=red}
\setbeamercolor{block body example}{bg=normal text.bg!90!black}
\setbeamercolor{block title alerted}{use={normal text,alerted text},fg=normal text.fg,bg=red}
\setbeamercolor{block title}{bg=blue}
\setbeamercolor{block title example}{use={normal text,example text},fg=example text.fg!75!normal text.fg,bg=red}
\setbeamercolor{fine separation line}{}
\setbeamercolor{frametitle}{fg=CTFred,bg=}
\setbeamercolor{item projected}{fg=black}
\setbeamercolor{normal text}{bg=black,fg=CTFlightgrey}
\setbeamercolor{palette sidebar primary}{use=normal text,fg=normal text.fg}
\setbeamercolor{palette sidebar quaternary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar secondary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar tertiary}{use=normal text,fg=normal text.fg}
\setbeamercolor{section in sidebar}{fg=black}
\setbeamercolor{section in sidebar shaded}{fg= grey}
\setbeamercolor{separation line}{}
\setbeamercolor{sidebar}{bg=red}
\setbeamercolor{sidebar}{parent=palette primary}
\setbeamercolor{structure}{bg=black, fg=green}
\setbeamercolor{subsection in sidebar}{fg=brown}
\setbeamercolor{subsection in sidebar shaded}{fg= grey}
\setbeamercolor{title}{fg=white,bg=}
\setbeamercolor{titlelike}{fg=brown}
\setbeamercolor{itemize item}{fg=CTFred}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{headline}{\vspace{0cm}\hspace{0.95\textwidth}\insertframenumber/\inserttotalframenumber\vspace{-9cm}}
\mode
There's some extra stuff in there that I didn't use but wanted to keep all of the color options in the file so I can modify it when I need to do fancy things. :)Save the file as beamerthemeCTF.sty in ~/Library/texmf/tex/latex/ (you might have to create the folder)
The next step is to put \usetheme{CTF} in your .tex file after \documentclass[mathserif]{beamer}
The last step is to add the background image. Save the picture below as ~/Library/texmf/tex/latex/CTFLab.pdf
Monday, September 12, 2011
Printers/Scanner on Mac
After a lot of searching I found drivers provided by Mac. They are downloadable from http://support.apple.com/downloads/#hp. Once I downloaded the drivers, suddenly, the printer and scanner worked at the same time!
Thursday, July 28, 2011
Keep mac from "swooshing" to a different space
defaults write com.apple.dock workspaces-auto-swoosh -bool NO
killall Dock
Note: if you want to restore the default behavior, run the first command with YES instead of NO. And then killall Dock to restart the dock.
Wednesday, July 27, 2011
ssh and scp easier
ssh username@DNS-name.eduor
scp file username@111.222.33.444:~/fileBy modifying your ~/.ssh/config file you can change the two previous commands to
ssh comp1and
scp file comp2:~/filewhere comp1 and comp2 are your names for the two computers and can be anything.
All you have to do is add a couple lines to you ~/.ssh/config file and you will save yourself a lot of typing. The steps below outline the proceedure:
- Open ~/.ssh/config in your favorite text editor (you may have to create the file)
- For each computer you ssh or scp to add a section to the file that looks like
Host computer_name
Hostname 111.222.33.444 (or DNS Name)
User username
ForwardX11 yes
computer_name is what you want to call the compter (comp1 and comp2 in the examples), 111.222.33.444 is the IP address for the remote computer (you can also use the DNS Name), username is the user on the remote computer.
Tuesday, July 26, 2011
Mac: Keyboard shortcut to launch program in current space
We'll start with opening a terminal window because it is easier.
- Launch AppleScript Editor
- Copy and paste the following code into the editor
tell application "Terminal"
do script ""
activate
end tell
- Save the file as ~/Library/Scripts/Open-Terminal.scpt
- Open Finder and go to the ~/Library/Scripts folder
- Open Quicksilver (if you do not have it install it from here)
- Click the small down arrow and click on Triggers
- Click the "+" sign to add a new HotKey
- Drag Open-Firefox.scpt from the Finder window into the window that opens
- Click on the Trigger column to change the Hot Key (shortcut key)
- Now when you press the Hot Key a new Terminal window should appear on whatever space you are currently on and open redirect.html which instantly loads www.google.com
- Launch AppleScript Editor
- Copy and paste the following code into the editor
tell application "Firefox"
open "~/Library/Scripts/redirect.html"
activate
end tell
this code tells Firefox to open and go to redirect.html - Save the file as ~/Library/Scripts/Open-Firefox.scpt
- Open Finder and go to the ~/Library/Scripts folder
- Create ~/Library/Scripts/redirect.html in a text editor and paste the following code into the file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Redirecting</title>
<meta http-equiv="REFRESH" content="0;url=http://www.google.com"></HEAD>
<BODY>
<p> Redirecting </p>
</BODY>
</HTML>
- Open Quicksilver (if you do not have it install it from here)
- Click the small down arrow and click on Triggers
- Click the "+" sign to add a new HotKey
- Drag Open-Terminal.scpt from the Finder window into the window that opens
- Click on the Trigger column to change the Hot Key (shortcut key)
- Now when you press the Hot Key a new Firefox window should appear on whatever space you are currently on



