GLIBCXX_3.4.9 Could Not Be Found with Apache Spark
Saliya Ekanayake
If you encounter an error similar to the following, which complains that
GLIBCXX_3.4.9 could not be found, while running an application with Apache Spark you can avoid this by switching Spark's compression method from snappy to something such aslzf....
Caused by: java.lang.UnsatisfiedLinkError: .../snappy-1.0.5.3-1e2f59f6-8ea3-4c03-87fe-dcf4fa75ba6c-libsnappyjava.so: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by.../snappy-1.0.5.3-1e2f59f6-8ea3-4c03-87fe-dcf4fa75ba6c-libsnappyjava.so)
There are a few ways how one can pass configuration options to Spark. The naive way seems to be through command line as,
--conf "spark.io.compression.codec=lzf"
On a side note, you can find what GLIBC versions are available by running
strings /usr/lib/libstdc++.so.6 | grep GLIBC
References
- A mail thread on this
- Spark configuration options
Referring Methods that Throw Exceptions in Java
Saliya Ekanayake
The ability to refer (pass) methods in Java 8 is a convenient feature, however, as a programmer you might face the situtaion where some code that seemingly follow the correct syntax to refer a method that throws an exception gives a compilation error of an
Unhandled Exception, which doesn't go away by wrapping the call in a try/catch or adding a throws clause to the method signature. See the following code,import java.util.function.Function;
public class PassingMethodsThatThrowExceptions {
public static int addOne(String value) throws NotANumberException{
int v = 0;
try{
v = Integer.parseInt(value);
} catch (NumberFormatException e){
throw new NotANumberException();
}
return v+1;
}
public static void increment(Function<String,Integer> incrementer, String value){
System.out.println(incrementer.apply(value));
}
public static void main(String[] args) {
increment(PassingMethodsThatThrowExceptions::addOne, "10");
}
}
This is a simple code, which has
- an
addOnefunction that takes in aStringvalue representing a number then adds1to it and returns the result as anint. - an
incrementfunction that simply takes a function, which can perform the increment and a value then apply the function to the value. - the
mainmethod that callsincrementwithaddOnefunction and value"10"
Note.
addOne function is declared to throw possible exception of type NotANumberException (the type of exception is NOT important here).
This code will result in following compilation error,
Error: java: incompatible thrown types exceptions.NotANumberException in method reference
If you use an IDE such as IntelliJIDEA it'll show
Unhandled Exception: NotANumberException for the increment method call in mainand adding try/catch will not work.
What's going wrong here? It's actually a mistake on your end.
The
increment function expects a function that takes a String and returns an int, but you forgot to mention that this method may also throw an exception of type NotANumberException.
The solution is to correct the type of
incrementer parameter in increment function.
Note. you'll need to write a new functional interface because you can't add
throws NotANumberException to thejava.util.function.Function interface that's used to define the type of incrementer parameter here.
Here's the working solution in full.
public class PassingMethodsThatThrowExceptions {
public interface IncrementerSignature{
public int apply(String value) throws NotANumberException;
}
public static int addOne(String value) throws NotANumberException{
int v = 0;
try{
v = Integer.parseInt(value);
} catch (NumberFormatException e){
throw new NotANumberException();
}
return v+1;
}
public static void increment(IncrementerSignature incrementer, String value) throws NotANumberException {
System.out.println(incrementer.apply(value));
}
public static void main(String[] args) {
try {
increment(PassingMethodsThatThrowExceptions::addOne, "10");
} catch (NotANumberException e) {
e.printStackTrace();
}
}
}
Also, note this is
NOT something to do with referring methods or Java 8 in general. You may face a similar situation even in a case where you implement a method of an interface and in the implementation you add the throws SomeException to the signature. Here's a stackoverflow post you'd like to see on this.
Hope this helps!
Blogging with Markdown in Blogger
Saliya Ekanayake
tl;dr - Use Dillinger and paste the formatted content directly to blogger
Recently, I tried many techinques, which will allow me to write blogs in markdown. The available choice in broad categories are,
- Use makrdown aware static blog generator such as Jekyll or something based on it like Octopress
- Use a blogging solution based on markdown such as svbtle
- Use a tool that'll either enable markdown support in blogger (see this post) or can post to blogger (like StackEdit)
First is the obvious choice if you need total control over your blog, but I didn't want to get into too much trouble just to blog because it involes hosting the generated static html pages on your own - not to mention the trouble of enabling comments. I like the second solution from and went the distance to even move my blog to svbtle. It's pretty simple and straightforward, but after doing a post or two I realized the lack of comments is a showstopper. I agree it's good for posts intended for "read only" use, but usually it's not the case for me.
This is when I started investigating on the third option and thought StackEdit to be a nice solution as it'll allow posting to blogger directly. However, it doesn't support syntax highlighting for code blocks - bummer!
Then came the "aha!" moment. I've been using Dillinger to edit markdown regularly as it's very simple and gives you instant formatted output. I thought why not just copy the formatted content and paste it in the blog post - duh. No surprises - it worked like a charm. Dillinger beatifully formats everything including syntax highligting for code/scripts. Also, it allows you to link with either Dropbox or Github where I use Github.
All in all, I found Dillinger to be the easiest solution and if you like to see a formatted post see my first post with it.
Weekend Carpentry: Baby Gate
Saliya Ekanayake
My 10 month old son is pioneering his crawling skills and has just begun to cruise. It's been hard to keep him out of the shoe rack with these mobile skills, so I decided to make this little fence.
Download Sketchup file
Download PDF file
Here's a video of the sliding lock mechanism I made.
Running C# MPI.NET Applications with Mono and OpenMPI
Saliya Ekanayake
I wrote an earlier post on the same subject, but just realized it's not detailed enough even for me to retry, hence the reason for this post.
I've tested this in FutreGrid with Infiniband to run our C# based pairwise clustering program on real data up to 32 nodes (I didn't find any restriction to go above this many nodes - it was just the maximum I could reserve at that time)
What you'll need
- Mono 3.4.0
- MPI.NET source code revision 338.
svn co https://svn.osl.iu.edu/svn/mpi_net/trunk -r 338 mpi.net- Also, download the Unsafe.pl.patch, which was originally available here
- OpenMPI 1.4.3. Note this is a retired version of OpenMPI and we are using it only because that's the best that I could get MPI.NET to compile against. If in future MPI.NET team provides support for a newer version of OpenMPI, you may be able to use it as well.
- Automake 1.9. Newer versions may work, but I encountered some errors in the past, which made me stick with version 1.9.
How to install
- I suggest installing everything to a user directory, which will avoid you requiring super user privileges. Let's create a directory called
build_monoinside home directory.mkdir ~/build_monoThe following lines added to your~/.bashrcwill help you follow the rest of the document.BUILD_MONO=~/build_mono PATH=$BUILD_MONO/bin:$PATH LD_LIBRARY_PATH=$BUILD_MONO/lib ac_cv_path_ILASM=$BUILD_MONO/bin/ilasm export BUILD_MONO PATH LD_LIBRARY_PATH ac_cv_path_ILASMOnce these lines are added do,source ~/.bashrc - Build automake by first going to the directory that containst
automake-1.9.tar.gzand doing,tar -xzf automake-1.9.tar.gz cd automake-1.9 ./configure --prefix=$BUILD_MONO make make installYou can verify the installation by typingwhich automake, which should point toautomakeinside$BUILD_MONO/bin - Build OpenMPI. Again, change directory to where you downloaded
openmpi-1.4.3.tar.gzand do,tar -xzf openmpi-1.4.3.tar.gz cd openmpi-1.4.3 ./configure --prefix=$BUILD_MONO make make installOptionally if Infiniband is available you can point to theverbs.h(usually this is in/usr/include/infiniband/) by specifying the folder/usrin the aboveconfigurecommand as,./configure --prefix=$BUILD_MONO --with-openib=/usrIf building OpenMPI is successfull, you'll see the following output formpirun --versioncommand,mpirun (Open MPI) 1.4.3 Report bugs to http://www.open-mpi.org/community/help/Also, to make sure the Infiniband module is built correctly (if specified) you can do,ompi_info|grep openibwhich, should output the following.MCA btl: openib (MCA v2.0, API v2.0, Component v1.4.3) - Build Mono. Go to directory containing
mono-3.4.0.tar.bz2and do,tar -xjf mono-3.4.0.tar.bz2 cd mono-3.4.0Mono 3.4.0 release is missing a file, which you'll need to add by pasting the following content to a file called./mcs/tools/xbuild/targets/Microsoft.Portable.Common.targets<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="..\Microsoft.Portable.Core.props" /> <Import Project="..\Microsoft.Portable.Core.targets" /> </Project>You can continue with the build by following,./configure --prefix=$BUILD_MONO make make installThere are several configuration parameters that you can play with and I suggest going through them either inREADME.mdor in./configure --help. One parameter, in particular, that I'd like to test with is--with-tls=pthread - Build MPI.NET. If you were wonder why we had that
ac_cv_path_ILASMvariable in~/.bashrcthen this is where it'll be used. MPI.NET by default tries to find the Intermediate Language Assembler (ILASM) at/usr/bin/ilasm2, which for 1. does not exist because we built Mono into$BUILD_MONOand not/usr2. does not exist because newer versions of Mono calls thisilasmnotilasm2. Therefore, after digging through theconfigurefile I found that we can specify the path to the ILASM by exporting the above environment variable.Alright, back to building MPI.NET. First copy the downloadedUnsafe.pl.patchto the subversion checkout of MPI.NET. Then change directory there and do,patch MPI/Unsafe.pl < Unsafe.pl.patchThis will say some hunks failed to apply, but that should be fine. It only means that those are already fixed in the checkout. Once patching is completed continue with the following../autogen.sh ./configure --prefix=$BUILD_MONO make make installAt this point you should be able to findMPI.dllandMPI.dll.configinsideMPIdirectory, which you can use to bind against your C# MPI application.
How to run
- Here's a sample MPI program written in C# using MPI.NET.
using System; using MPI; namespace MPINETinMono { class Program { static void Main(string[] args) { using (new MPI.Environment(ref args)) { Console.Write("Rank {0} of {1} running on {2}\n", Communicator.world.Rank, Communicator.world.Size, MPI.Environment.ProcessorName); } } } } - There are two ways that you can compile this program.
- Use Visual Studio referring to MPI.dll built on Windows
- Use
mcsfrom Linux referring to MPI.dll built on Linuxmcs Program.cs -reference:$MPI.NET_DIR/tools/mpi_net/MPI/MPI.dllwhere$MPI.NET_DIRrefers to the subversion checkout directory of MPI.NETEither way you should be able to getProgram.exein the end.
- Once you have the executable you can use
monowithmpirunto run this in Linux. For example you can do the following within the directory of the executable,mpirun -np 4 mono ./Program.exewhich will produce,Rank 0 of 4 running on i81 Rank 2 of 4 running on i81 Rank 1 of 4 running on i81 Rank 3 of 4 running on i81wherei81is one of the compute nodes in FutureGrid cluster.You may also use other advance options with mpirun to determine process mapping and binding. Note. the syntax for such controlling is different from latest versions of OpenMPI. Therefore, it's a good idea to look at different options frommpirun --help. For example you may be interested in specifying the following options,hostfile=<path-to-hostfile-listing-available-computing-nodes> ppn=<number-of-processes-per-node> cpp=<number-of-cpus-to-allocate-for-a-process> mpirun --display-map --mca btl ^tcp --hostfile $hostfile --bind-to-core --bysocket --npernode $ppn --cpus-per-proc $cpp -np $(($nodes*$ppn)) ...where,--display-mapwill print how processes are bind to processing units and--mca btl ^tcpforces to turn offtcp
That's all you'll need to run C# based MPI.NET applications in Linux with Mono and OpenMPI. Hope this helps!
Avoid Comcast DNS Hijacking in Ubuntu
Saliya Ekanayake
Recently I switched to Comcast from AT&T because of an interesting deal on internet. Today I was on my Ubuntu machine in a different network and ran into the issue of not being able to connect to internet. After doing bit of looking into I figured that DNS is not working properly. I was getting a reply that had "hsd1.in.comcast.net" when I tried to do a host lookup (e.g. host -a google.com).
Then when I opened the /etc/resolv.conf I found that Comcast has inserted its nameservers into that and after removing those entries and setting the nameserver to Google's 8.8.8.8 I was able to connect and browse as usual.
Hope this helps someone in a similar situation!
Then when I opened the /etc/resolv.conf I found that Comcast has inserted its nameservers into that and after removing those entries and setting the nameserver to Google's 8.8.8.8 I was able to connect and browse as usual.
Hope this helps someone in a similar situation!
Get PID from Java
Saliya Ekanayake
This may not be elegant, but it works !
public static String getPid() throws IOException {
byte[] bo = new byte[100];
String[] cmd = {"bash", "-c", "echo $PPID"};
Process p = Runtime.getRuntime().exec(cmd);
p.getInputStream().read(bo);
return new String(bo);
}
C# and Java Operators Thread Safety
Saliya Ekanayake
Java and C# both have compound assignment operators and the increment/decrement operators. For example see http://msdn.microsoft.com/en-us/library/6a71f45d.aspx for a list of C# operators and http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html for the Java version.
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
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
8:55 PM
C#
,
compound assignment operators
,
concurrency
,
java
,
thread safety
Weekend Carpentry: Shaver Holder
Saliya Ekanayake
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
Saliya Ekanayake
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.
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.
7:24 AM
Subscribe to:
Posts
(
Atom
)

