Friday, May 23, 2014

BASH PS1 modification for screen

I use screen a lot, so it can be confusing when switching between separate screen instances. I often use it remotely, and used to accidentally make the mistake of using CTRL - A - D (to detach from screen session) too many times, and the final time CTRL - D is registered by BASH, which terminates my remote session connection.

Instead: always know where you are! Modify PS1 in ~/.bashrc (it might work, and be more appropriate, to put it in ~/.screenrc )

if [ $TERM = screen ]
then
    PS1="(screen ${STY#*.}) $PS1"

fi;

The string substitution bit is just there to remove the process ID from the PID.screen_name $STY variable

Demo:

nick@machine:~$ screen -S project2
(screen project2) nick@machine:~$





Friday, January 31, 2014

mex compilation on OS X 10.9 with OMP reliant code

as of now, clang doesn't support OMP (not Orthogonal Matching Pursuit, Open Multi-Processing)

in MATLAB 2013a, mex defaults to using XCode & clang to compile mex scripts

I edited /Applications/MATLAB_R2013.a/bin/mexopt.sh

to have the following at the bottom

CC='/opt/local/bin/gcc-mp-4.8'  
          SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk'  
MACOSX_DEPLOYMENT_TARGET='10.9'  
ARCHS='x86_64'  
CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"  
CFLAGS="$CFLAGS -fexceptions"  
CLIBS="$MLIBS"  
COPTIMFLAGS='-O2 -DNDEBUG'  
CDEBUGFLAGS='-g'  
       
CLIBS="$CLIBS -lstdc++" 
CXX='/opt/local/bin/g++-mp-4.8'
CXXFLAGS="-fno-common -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CXXLIBS="$MLIBS -lstdc++"
CXXOPTIMFLAGS='-O2 -DNDEBUG'
CXXDEBUGFLAGS='-g' 
LD="$COMPILER"
LDEXTENSION='.mexa64'
LDFLAGS="-pthread -shared"
LDOPTIMFLAGS='-O'
LDDEBUGFLAGS='-g'


note that CC and CXX refer to versions of gcc I've installed via MacPorts

even if your code doesn't use OMP, using gcc should still work on Mac

at the MATLAB prompt, I then ran

>>> mex -setup

to select this edited file as the compilation options script for my .matlab user profile