MTH 654 LAB 2

In this lab you learn how to operate in a terminal-based computing environment based on Unix (Linux), and how to use a compilable programming environment (in contrast, MATLAB is an interpretive environemnt). Since most students work in MLC on Windows-based machines, we will actually use Cygwin which is a Unix emulator under Windows.
Rules:
  • This assignment will vary depending on your initial skill level (whether you know Unix, Fortran, C etc.). I ask that you skip the parts that are easy for you and move on to steps/projects that are new for you. (If all steps are easy, then go straight to the last Project 5).
  • You can use either Fortran, or C, or both. The choices may affect what you will have to learn later. I ask that you at least take a look at both so you get an idea of the code structure.

    Our MPI examples will be in Fortran and GPU CUDA in C so this class is preparing you for this.

  • Turn in solutions to at least two of the listed projects of your choice; the projects are listed in the order of increasing difficulty.
  • If necessary, go to the assignments page to get reference information on Unix, Fortran, or C.
  • Ask for help if you get stuck.

Synopsis:

  • We use Cygwin and Cygwin-X which emulate Unix and X-Windows on Windows machines. This is useful to us because
    • while learning Unix you can for the moment use your favorite Windows editor and file manager ... to see the correspondance between what is happening simultaneously under Unix and Windows.

      In future labs you will use a different (remote) computer to whch you will log in from this one. On that remote machine you will be only using command line Unix/Linux commands.

  • You will use Cygwin to implement your first programs in Fortran or/and in C in a Unix environment.
    Implement = write Fortran/C code + compile it + run it.

Steps and project(s):
  • Get familiar with Unix environment
    • Click on the icon Cygwin on your Desktop to start Cygwin.
    • Where are you ... ? ... move within your file system (and home directory)
      pwd
      mkdir lab2
      ls
      cd lab2
      pwd
      go back to where you started cd ..
      pwd
      ls
      Now move to the Desktop. Ha !
    • Learn how to create a text file, see its contents, and copy and move files: Explore (use man pages) commands cat, cp, mv, rm, rmdir
      cat > myfile.txt
      type anything you want ... and finish with Ctrl-D
      cat myfile.txt
    • Now copy a few files, move between folders ...

    Now you are an expert, find out who you are and on which system you really are...
    whoami ; uname
  • Project 1. Run a baby example code written in Fortran or in C
    • download the file code to Desktop and place it in your cygwin lab2 folder (the one you created)
    • compile the code (and link) (NOTE: the program has intentional mistakes which you have to correct)
      g77 hellof.f
    • run: (the program has now a default name: a.exe, on Unix it gets the name a.out)
      ./a.exe
    • compile and link and give it a name
      g77 -o hellof.exe hellof.f
    • run:
      ./hellof.exe

    The program computes the norm inefficiently. Please correct. EXPLAIN.
    Make it compute also the L1, Linfty norm of your birthday as well as the average of the random numbers.
    The program draws from uniform distribution and computes ... ? EXPLAIN what you expect to see.
    Helpful hints
    • memory allocation in Fortran 77 is static
    • Fortran code MUST start in column 7
    • put a character in the first column for lines with comments
    • you can also put comments after a ! in the middle of the line
    • use IMPLICIT NONE: this has saved many from mismatched type death
    • This is an useful when comuting Linfty norm
      if (mymax.lt.mynumber) then
      mymax = mynumber
      endif