User Tools

Site Tools


workshops:hpcprac1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
workshops:hpcprac1 [2015/06/28 14:43]
kevin
workshops:hpcprac1 [2021/12/09 16:42] (current)
Line 1: Line 1:
-=====Practical 1: Linux Shell=====+=====Practical 1: Linux Shell for Programmers=====
  
 **Aim:** to build and install in your //home// directory a library and and application. **Aim:** to build and install in your //home// directory a library and and application.
 +
 +====Slides====
 +
 +The slides for this morning's lecture on Linux are [[workshops:hpcslides|available]].
  
 ====Logging in==== ====Logging in====
  
-Download and install putty-ssh and connect to ''ranger.ace.chpc.ac.za'' using the username (schoolNN) and password provided.+Download and install putty-ssh and connect to ''lengau.chpc.ac.za'' using the username (**studentNN**) and password provided.
  
 ====Build and install zlib library==== ====Build and install zlib library====
Line 15: Line 19:
 Copy the zlip source code tar file from my home directory. Copy the zlip source code tar file from my home directory.
  
-  cp /home/kcolville/??? .+  cp /home/student00/??? .
  
 Fill in the ??? with the correct path and file name. Fill in the ??? with the correct path and file name.
Line 21: Line 25:
 Move the tar file into the new directory: Move the tar file into the new directory:
   mv zlib-1.2.8.tar.gz src/   mv zlib-1.2.8.tar.gz src/
 +
 +> Note that the version available is probably newer than 1.2.8 --- modify these instructions accordingly.
  
 Untar the file Untar the file
Line 29: Line 35:
 Load the correct environment variables using the tool "module": Load the correct environment variables using the tool "module":
  
-  module load gcc/gcc-4.9.2/4.9.2+  module load gcc/??? 
 + 
 +**Fill in the correct information for the ??? above.**
  
 Prepare your own local directory structure: Prepare your own local directory structure:
Line 46: Line 54:
   make install   make install
  
 +Verify that everything is in ''~/local''
 +
 +  ls -R ~/local
 +  
 +
 +====Build a simple application using your own zlib====
 +
 +Copy the ''zpipe.c'' file from my home directory (student00) into your ''src'' directory.
 +
 +> You should be able to work out what the commands are by now
 +
 +Edit the ''zpipe.c'' file to change the line that reads
 +
 +  #include "zlib.h"
 +
 +to
 +
 +  #include "zzzlib.h"
 +  
 +and change the name of the ''zlib.h'' file in your ''~/local/include'' directory to match.
 +
 +Now compile the object file (ends in ''.o''):
 +
 +  gcc -c -o zpipe.o -I ~/local/include zpipe.c
 +
 +This should find the ''zzzlib.h'' file without errors.
 +
 +> Try the ''gcc'' command without the ''-I ~/local/include'' to what happens.
 +
 +Now build the ''zpipe'' executable
 +
 +  gcc -o zpipe -I ~/local/include zpipe.c -L ~/local/lib -lz
 +
 +> The **order** of the command line options and arguments is important
 +> The commands to //link// the library file must come **after** the commands to //compile//.
 +
 +  
 +If there are no errors and ''ls'' shows you a ''zpipe'' file (in green) you are done.
 +
 +You can test the new ''zpipe'' program by compressing and then uncompessing a file.
 +
 +  ./zpipe < test > test.z
 +  ./zpipe -d < test.z > test2
 +  cmp test test2
 +
 +There should be no difference between ''test'' and ''test1''.
 +
 +====Install zpipe====
 +
 +Now it is inconvenient that you have to always be in the ''src'' directory to use ''zpipe'' or to have to always type the full path to it: ''~/src/zpipe''
 +
 +Install ''zpipe'' in your local execultable tree
 +
 +  cp zpipe ~/local/bin
 +  
 +To make sure that the shell can find ''zpipe'' you need to include your ''local/bin'' in the ''PATH'' environment variable:
 +
 +  export PATH=~/local/bin:$PATH
 +  
 +Now you need only type ''zpipe'' to use it anywhere.
 +
 +  cd
 +  zpipe --help
 +
 +To make sure that each time you login that the ''PATH'' variable contains your ''local/bin'' directory, just add the ''export'' command to your ''.bash_profile'' file.
 +
 +  nano .bash_profile
 +  
 +And add (or edit the existing line) to have:
 +
 +  PATH=$HOME/local/bin:$PATH
 +  export PATH
 + 
 +
 +====References====
 +
 +  * ''zpipe.c'' is from [[http://zlib.net/zlib_how.html|zlib Usage Example]]
 +  * [[http://zlib.net/|zlib home]]
  
  
/app/dokuwiki/data/attic/workshops/hpcprac1.1435495395.txt.gz · Last modified: 2021/12/09 16:42 (external edit)