Pages

Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

Tuesday, October 13, 2015

[OSX] OpenMP on OSX

If you are new to openMP and your operation system is OSX. You may encounter similar problems when compiling your first openMP code as I did.

Typically, the tutorial will ask you compile your source code with

g++ -fopenmp mycode.cpp

However, you may get confusing error messages like
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I will not talk about the reasons in detail, all you/I have to know is that this is because on OSX our dear compiler g++ is  by default linked to clang (i.e. when you call g++ on OSX, we actually call clang), which is another compiler that has not support openMP yet. So the solution is: use another compiler supporting openMP.

Version 1: Download the clang-omp
It seems that this issue only happens on OSX, so a OSX-only solution is sufficient: use Homebrew to install another compiler named clang-omp.

brew install clang-omp
Then use this when compiling the code

clang-omp -fopenmp mycode.cpp


Version 2: Compile and isolate the latest gcc (still from Homebrew)
One alternative way is to compile and install another gcc from source code. In this way, we need to download the gcc source code and its dependencies by our own and compile and install them. That is, we are going to install gmp, mpc, mpfr before gcc, and we will put this compiler under a directory/prefix like the others (e.g. /usr/local/gcc5.0.2/)

However, I have encountered some issues so I switched back to Homebrew for installing them.
(you probably do not need to install the dependencies one by one, but I did not test this :p)

brew install gmp
brew install mpc
brew install mpfr
brew tap homebrew/versions
brew install gcc5 --enable-gcc

After the above steps, the gcc5 from Homebrew will be under something like /usr/local/Cellar/gcc5/5.2.0/bin
Next, we should modify our environment variable to easily call it

Let's say your shell file is ~/.bashrc (mine is ~/.zshrc though)
edit ~/.bashrc and add the statements like (your latest gcc might be different)

export GCC5_HOME='/usr/local/Cellar/gcc5/5.2.0' export PATH=$PATH:$GCC5_HOME/bin/ alias gcc5='g++-5'

Reload the shell (or reopen your terminal)
then we can use gcc5 to compile the openMP files and remain the gcc/clang untouched

gcc5 -fopenmp mycode.cpp


Reference:
https://solarianprogrammer.com/2015/05/01/compiling-gcc-5-mac-os-x/

Sunday, October 6, 2013

[OSX] MacVim

The way I see it, as a programmer, it is strongly recommended that use plain text editor to develop at the beginning; By doing so, you won't rely on the IDE too much thus you learn more fundamental and important things.

On the other hand, when the project become larger and larger, a powerful IDE is needed to help us to solve boring and trivial things such as file renaming, auto-completion, syntax highlighting, indent checking, etc.

But sometimes, I just want to write a simple script! And I don't want a  plain text editor nor complicated IDE.  So I need a powerful text editor with some fancy plugins like auto-completion, indent checking.
Today, I want to write down some notes to set up MacVim, Macintosh version of vim,


vim configuration:
~/.vimrc

MacVim configuration
~/.gvimrc

MacVim will load .vimrc first, then .gvimrc, so put general configuration in .vimrc, and set up GUI in .gvimrc.


Install MacVim via MacPort rather than official website:
sudo port install macvim + cscope + python27

Friday, September 27, 2013

[Linux] Run GUI on command-line-only server

Why?
When you need to connect to a linux server, which does not support GUI, to use the computational power and programs but still want to use the GUI of some programs (not the entire OS).  For example, Matlab, Eclipse.

X11 is what your want! With the help of X11, you can use run your program on a remote server but open a GUI on your client machine using the resource (X11) locally.  In short, you just need to install X11 on your client machine.

How it works?
Install X11 on your client machine, and connect to your server with a special ssh connection.

For Linux & OSX
Just add an option -X in your ssh connection command
ssh -X spencer@yourmachine.com

then you can use your program (e.g. Matlab) with a GUI in this session.
Window (via putty)
Add an option 'Enable X11 Forwarding' in the left panel























If it does not work, you need to install X11 first.  I install it via Cygwin with just several clicks while installing the packages.  Then you can try it again (still use the putty).

Your can see my another post for details of installing Cygwin.
http://spencermurmur.blogspot.tw/2013/09/windows-work-as-if-using-linux-shell.html



Monday, September 9, 2013

[Ubuntu] How I build up the environment on Ubuntu

In this post, I will use command line so that I do not need to care about the issues caused by different graphic user interfaces.
(Don't be afraid of command line! You can just copy & paste if you are not interested in it.)

Operation System: Ubuntu 12.04
Check the Ubuntu version again
lsb_release -a





Update the system
sudo apt-get update
sudo apt-get upgrade

Set default editor to vim
sudo update-alternatives --config editor
Enter your passwd








Press 3 (vim.basic) and enter

Set the administrator privilege
sudo visudo
This command uses default editor to open /etc/sudoers to help you check the format.
Assume you want to give administrator privilege to user 'spencer' and group 'adm'







Check the disk
df -h










Setup a shared directory
Assume you want to create a shared directory /home/shared/
(please make sure the parent directory, i.e. /home has sufficient space)

sudo mkdir /home/shared/
sudo chmod -R 777 /home/shared/

Set the default permission for this directory using ACLs (Access Control Lists)
sudo vim /etc/fstab









Add ACL option to /home, which is the parent directory







Then remount it
sudo mount -oremount /home
Now, use the following command to set the default ACL:
sudo setfacl -dm u::rwx,g::rwx,o::rwx /home/shared/
It means that default permission of directories and files under /home/shared/ will be 777 (Everyone can read, write, and execute).
Create softlinks (like Shortcuts on Windows) in every user's home directory (For example: spencer), so that the users can upload their data directly to the shared directory.
sudo ln -s /home/shared/ /home/spencer/shared 
Install the Git
Ubuntu 12.04 is accompanied with git.

But you still to learn how to generate your security key to connect to remote repositories.
ssh-keygen


















Press enter to save the file under default location
Input the password for this key
You will need the content of id_rsa.pub file, use the follow command to copy the content to clipboard.
pbcopy < ~/.ssh/id_rsa.pub

Install Python and useful packages
  • iPython
  • Scipy
  • Numpy
  • Matplotlib
Ubuntu 12.04 is accompanied with them.

Install vim plug-ins
  • pydiction
  • taglist
  • NERDtree
Install curl
sudo apt-get install curl

Setup VNC server
Virtual Network Computing (VNC), a way to connect to the GUI.

sudo apt-get install vnc
Setup the vnc password
vncpasswd
Edit your ~/.vnc/xstartup
   #twm
  gnome-session &
Start the your vncserver by this
 vncserver -geometry 1920x1080
then your session would have a window with 1920x1080 volume






For connection, use your favorite vnc client software (RealVNC, UltraVNC, etc), and the port you need to enter is 5900+the display number (1 in this case) = 5901.  You also need to enter the VNC password.
Other Packages for productivity

1. oh my zsh: Another shell with git friendly theme.

    Install zsh
    sudo apt-get install zsh
    git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

    Change the default shell to zsh
    chsh -s /bin/zsh
    then restart the machine.
    BTW, if you want your bash shell back, just use this
    chsh -s /bin/bash

    Thursday, April 18, 2013

    Thursday, January 17, 2013

    [OSX] Create bootable USB drive on OSX

    How to create a bootable USB drive when you only an OSX-based computer?

    For readers as lazy as me: Just follow the colored text.


    In my case, I want to reinstall my PC with Ubuntu, using a ISO files.
    1. Prepare your source file

        For example, ubuntu.iso

    2. Convert the .iso files to .dmg
        Here, I want my .dmg file named as ubuntu.dmg
        hdiutil convert -format UDRW -o ~/path/to/ubuntu.img ~/path/to/ubuntu.iso

    3. Wipe you USB drive (using Disk Utility)

    1. Open up Disk Utility (it’s in /Applications/Utilities/).
    2. Click you USB root drive on the left panel
    3. Click the 'partition' tab on the right panel
    4. Choose the 'Volume Scheme'  as '1 partition'
    5. Set the 'Format' as Free Space
    6. Click 'Apply'
    7. Unmount the drive (Do not eject)


    4. Put you .dmg file into your USB drive

    1. Find the USB disk index by
      diskutil list
      It is disk1, in my case.
    2. use 'dd' to transfer your file into the raw drive
      sudo dd if=./ubuntu.dmg of=/dev/rdisk1

    5. Be patient
    Your may see messages like this when it is done:
    1421912+0 records in
    1421912+0 records out
    728018944 bytes transferred in 11020.757758 secs (66059 bytes/sec)



    Reference
    http://www.ubuntu.com/download/help/create-a-usb-stick-on-mac-osx
    http://evan.borgstrom.ca/post/1314205955/osx-bootable-usb-from-iso

    Thursday, October 4, 2012

    [OSX] Show full path in Finder window

    Enter the command
    defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

    Enter this to activate the effect
    killall Finder

    Thursday, June 7, 2012

    [OSX] Convert BIG5 file to UTF8

    I have been trying to transform my works from Windows to OSX.  However, in a addition to a powerful text editor (like Notepad++ on Windows), the most difficult things to me is how to open the files encoding in BIG5 which is what Windows uses for encoding traditional Chinese.

    The simplest way to convert the Big5 files to utf8 might be using an embedded converter.

    Open Terminal and type this
    iconv -f big5 -t utf8 [your_input_file] > [your_output_file]


    EDIT: I have found some useful text editors to do conversion.

    In general:
    1. Enable Big5 encoding character set in preference.
    2. Open the Big5 files using the interface.
    3. Save the file as UTF8.

    TextWrangler
    1. Enable Big5
    2. File->Open..., read as Big5
    3. File->Save as..., Encoding UTF8

    A simpler way:
    1. Enable Big5
    2. Drag and drop
    3. File->Reopen Using Encoding..., Big5
        (Or, click on the toolbar below text editing area)
    4. Save


    Fraiser(Smultron)
    Similar to TextWrangler, open the file using Big5, then
    Text->Reload Text Using Encoding..., UTF8,
    and save.

    Saturday, April 7, 2012

    [Python] Install matplotlib on OSX via MacPort

    OS: OSX 10.07(Lion)
    Python version: 2.7.1

    Install numpy:
    1. run the SuperPack Installer
    Or
    2.
    sudo port install py27-numpy
    (I recommend install py27-scipy too)


    Install iPython:
    sudo port install py27-ipython

    Install matplotlib:
    sudo port install py27-matplotlib

    MacPort put the programs under /opt/local/bin or /opt/local/sbin for default
    Make sure the path is included in your PATH:
    vi ~/.bash_profile

    Add this if not found
    export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    and I also add this:
    alias ipython=ipython-2.7


    ****NOTE***
    Because MacPort install everything under /opt/local/, where is not the system's default directory.
    then if you type python, it would fire the system python under /usr/bin/, not the MacPort version
    thus, you can't import matplotlib

    Please add these to set MacPort python as default
    sudo port select --set python python27

    or an naive way:
    add this in ~/.bach_profile
    alias python=/opt/local/bin/python27

    One more thing, if you use Pydev in Eclipse, do not forget to change the python interpreter
    Preference->PyDev->InterpreterPython-> 
    add a new interpreter, find it under /opt/bin/, and put it at the top as highest first choice. 

    %%sample code
    from pylab import *
    a = [[1,2],[100,400]]
    plot(a)
    savefig('test.png')

    reference: http://astrofrog.github.com/macports-python/

    Monday, February 20, 2012

    [Android] Android + Eclipse on Mac

    1.Download JDK
      
      developer.apple.com

      Click the 'Resource' at the top bar to find the package suit your os

      install it, we assume the path (JDK)is:

      /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Commands



    2. Download Android SDK
       
        http://developer.android.com/sdk/

       Choose the suitable version


       Extract it, here, we assume you put the extracted file under : '/Library/android-sdk-macosx'
      $ cd  /Library/android-skd-macosx/tools
      $ ./android

      Choose those version of Android SDK you wish to develop on, then 'Accept all'


    3. Download Eclipse and android ADT plug-in
        http://www.eclipse.org/downloads/

        Install and open Eclipse

        Click Help -> Install New Software...

        Click and 'Add...' button on the right side of 'With with'

        Enter you self-description in Name field, say, 'Android Development Kit (ADT)'
        fill the location filed with: 'https://dl-ssl.google.com/android/eclipse/'

        Install 'Android DDMS' and 'Android Development tools' at least
        (If there are error messages under Win7, try running your eclipse as Administrator)

        Click Eclipse -> Preferences -> Android    and set the SDK location as:
        /Library/android-sdk-macosx

    Sunday, February 19, 2012

    [Git] Git on your MAC

    [By macport]
    1. Install macport at http://www.macports.org/install.php

    sudo port selfupdate 

    sudo port install git-core

    For default, it will be installed in
    /opt/local/bin/git

    Note:
    Xcode package include git also, its path is:
    /usr/bin/git


    GUI for git
    http://www.sourcetreeapp.com/
    or on AppleStore
    http://itunes.apple.com/us/app/sourcetree/id411678673


    [w/o macport]
     Download the installer for OSX
     http://code.google.com/p/git-osx-installer/


    Initialize the current directory:
    git init
    Add the current directory to tracking repository
    git  add .
    Commit all the file under the current directory with message 'XXX'
    git commit -a -m 'XXX'
    Modify the commit message
    git commit --amend -m 'new message'
    Name the last commit file as 'ver1.0' (branch)
    git tag ver1.0
    Show all file whose version is 'ver1.0'
    git show ver1.0[:[spec file]]
    Show the message
    git show HEAD
    show last message
    git show HEAD^
    Checkout (restore) all the files to commit 'ver1.0'
    git reset ver1.0
    Checkout (restore) to last commit
    git reset HEAD^

    Work with a remote repository
    http://spencerimp.blogspot.tw/2013/10/git-how-to-use-git-on-bitbucket.html


    You can use option -h to know detail about the command


    reference
    http://tkg.im.ncue.edu.tw/?p=755