Homework 3 (Due 6 pm, Monday, 10/30/2017)ΒΆ

Please submit your homework to your git repo by 6 pm, Friday, 10/30/2017. For Problem 1, you also need to make your website viewable online. This means that you need to provide your web address to both Instructor and TA in order for us to view your website (a file website_address.txt containing your web address under hw3/prob1 directory in your git repo sounds like a good idea!).

For each problem in Problems 2, 3 and 4, create a subdirectory for each, e.g., hw3/prob1, etc. and please submit:

  1. all your source codes (i.e., all the given example codes with your own modifications. Please work on the codes to add your own modifications, change things, leave comments, etc.),
  2. a short note how to run your codes (e.g., a text file for each problem such as Readme.prob2, etc. which will include compiler flag options, or the use of makefile, etc.), and
  3. a report describing your work/findings (pdf).
  1. Let’s learn how to host your one personal webpage on a webserver. For this, you are going to setup your own website on the UCSC web server which is freely available for any members of UCSC. Later on, I encourage you learn how to polish your webpage over the quarter, post your academic work, update your research schedules, etc. Please note that you are going to do build a good looking website as part of the final coding project in this class. So, let’s begin to learn about it.

    (1) First step: Go visit the UCSC website on personal homepage and carefully read the how-to instruction on setting up and publishing your web page.

    (2) Second step: Login to the webserver using your UCSC ID, say, myID (where your UCSC email is myID@ucsc.edu) and your CruzID Blue password:

    ssh -Y myID@sftp.ic.ucsc.edu
    

    and then you’re prompted to type in your password which is your CruzID Blue password.

    Opon login, you will see a directory public_html, where you are going to upload your html files to post your website. At this point, you will see nothing there.

    (3) Third step: You now need to design your website. What we are going to do is to use Sphinx in order to build your website. To install Sphinx, you will first need to download one of the Python packages (see Items for the Class). For instance, installing Anaconda will be sufficient. Go to the Sphinx website and follow the instruction for download, that is:

    $ pip install -U Sphinx
    

    (4) Fourth step: Upon installing Anaconda and Step (3), you should be ready to use Sphinx to buid your website. Make sure if you can now use a Sphinx command by checking:

    $ which sphinx-quickstart
    $ /Users/dongwook/anaconda/bin/sphinx-quickstart
    

    If you don’t see a path like this, your Anaconda installation is not complete in the worst case. Most likely you will just need to add your anaconda path in your .bash_profile. For instance, adding a line as the following will fix the problem assuming you installed anaconda under your $HOME directory, say, $HOME/anaconda:

    $ export PATH="$HOME/anaconda/bin:$PATH"
    

    and make sure you source it using:

    $ source $HOME/.bash_profile
    

    or open a new terminal.

    Now you run the command line:

    $ sphinx-quickstart
    

    upon which you will see questions for initial configuration and you answer them. This will create a source directory with conf.py and a master document called index.rst. Don’t know what to answer? Don’t be afraid, there are default answers at the end of the questions, and you can always go with them first and fix them later.

    In case you want to fix your setup configuration, you can manually modify conf.py file at the top level directory.

    (5) Fifth step: Watch a quick Youtube video tutorial on Sphinx and learn how to start working on your webdesign (For example, at this step, you are going to edit those files with .rst extensions, beginning with the master file index.rst.).

    When you do this, please make a directory under your git repo (not the course git repo) and work on there. You can name it such as Sphinx_web. So, in case you already have a directory like ams209_Einstein, you should see:

    $ ls
    $ ams209_Einstein              Sphinx_web
    

    Make sure you make this new directory Sphinx_web git version controlled, and push it to your own git repo.

    (6) Sixth step: Upon following the Youtube instruction under your Sphinx_web directory, you should be able to view your Sphinx website locally. You now want to upload the contents in Sphinx_web/_build/html/ to the remote UCSC website under your account, myID@sftp.ic.ucsc.edu. There are two ways to upload the contents in Sphinx_web/_build/html/ to myID@sftp.ic.ucsc.edu:~/public_html/.

    (a) First way is to use scp command:

    $ cd Sphinx_web/_build/html/
    $ scp -r * myID@sftp.ic.ucsc.edu:~/public_html/
    

    (b) Second way is to use sftp command (please read more on sftp):

    $ cd Sphinx_web/_build/html/
    $ sftp  myID@sftp.ic.ucsc.edu   --> this will log you onto the remote machine sftp.ic.ucsc.edu
    $ cd public_html
    $ put -r * ./
    

    During the process of building your web locally on your computer using Sphinx, push your local changes to your git repo, make revision histories, and be free of losing any data!

    (7) Seventh step: You are now ready to view your online webpage you just posted. Use your web brower to open:

    http://people.ucsc.edu/~myID
    

    (8) Eight step: Bravo! Congratulation! You just posted your own website on the public domain. Follow Step 4 in UCSC website on personal homepage in order to link your site to make more visible. Make sure you let me and TA know about your link address.

  2. Practice your Fortran module-based programming by studying the Fortran sample code to find a root of a given function (see Fortran Example – Newton’s method to find a root). Solve all 8 exercise problems.

    The sample program implements a Newton’s method by successively searching for a better approximation to one of the roots of a real-valued function.

    Understanding the sample code is very crucial because the code will serve as a good reference programming example for the following homework problem 3.

  3. Let’s consider again to solve the \pi approximatation problem from Homework 2. This time, however, you’re going to program modular based implementations where you need to split your code into several different pieces. The code splitting should be designed carefully based on the role and functionality of each subroutine. Here is a suggestion for the code split and the organization (the followings are just a suggestion and you are welcome to come up with your own code design, which is better!):

    1. makefile (Yes, you will need this)

    2. pi_driver.F90 (a driver routine which calls the following subroutines)

      1. setup_module.F90 (initialize parameters from reading in a runtime parameter file, say, pi_approx.init.

      2. pi_module.F90 (a module implementation which include a subroutine called pi_summation.F90)

      3. pi_summation.F90 (a subroutine in pi_module.F90 which sums the series to evaluate the approximated \pi_{appx}.)

      4. pi_errorCheck.F90 (checks if the \pi_{appx} is accurate enough by comparing with a user specific threshold value – this is one of the runtime parameters in pi_approx.init file.)

      5. pi_writeOutput.F90 (writes output consisting of the iteration history of summation number

        N, \pi_{appx}, threshold value, and residual (or diff).

    Finally, plot the history of approximated \pi (y axis) versus number of summations N (x axis) using GNU plot.

  4. In this problem, you are going to practice to write four different types of Fortran 90 (potential) coding error, each of which is to be tested and debugged by Valgrind. Your implementations will exercise the following three types of Valgrind Memcheck detections:

    • Valgrind monitors memory leaks associated with out-of-bound array operations.
    • Valgrind monitors uninitialized variables. However, it does not complain unless such a variable is used in a way that means its value affects the program’s results, that is, the value is printed, or computed with. Simply copying the unitialized data to another variable is of no concern.
    • Valgrind checks reading/writing memory errors after it has been free’d.

    Based on the above facts, you are asked to:

    1. Write three Fortran routines each of which associates with one of the above three cases. In each case, Valgrind should successfully produce line numbers of potential bugs, or presumably the origin of bugs, in your source files when producing its error message.
    2. Write one Fortran routine with any potential issue(s) listed above but Valgrind fails to produce any line numbers when producing its error message.

    Use the template code below and modify it to do Parts a and b:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    program buggy_code_1
      !!
      !! You are going to use this template to write:
      !! 
      !! 1. buggy_code_1.f90
      !!     (that has an issue with memory leak
      !!      whose buggy line number(s) is(are) detectable by Valgrind)
      !! 
      !! 2. buggy_code_2.f90
      !!     (that has an issue with uninitialization
      !!      whose buggy line number(s) is(are) detectable by Valgrind)
      !!
      !! 3. buggy_code_3.f90
      !!     (that has an issue with reading/writing memory errors after free'd
      !!      whose buggy line number(s) is(are) detectable by Valgrind)
      !!     
      !! 3. buggy_code_4.f90
      !!     (that has any potential issue(s)
      !!      whose buggy line number(s) is(are) NOT detectable by Valgrind)
      !!
      !! Make sure you use useful Fortran dubugging flags
      !! to compile your source code before running Valgrind.
    
    
      !! DO NOT CHANGE BETWEEN LINE 25 AND LINE 29 ----
      implicit none
      integer ( kind = 4 ) :: n
      real (kind = 8), allocatable :: x(:)
    
      n = 10
      !! DO NOT CHANGE BETWEEN LINE 25 AND LINE 29 ----
    
    
    
      
      !!  your implementation goes here  !! 
    
    
    
      
      !! DO NOT CHANGE BELOW THIS LINE ----------------
    end program buggy_code_1
    

    Make sure you use the Fortran debugging flags to compile your source codes before running Valgrind against your executables. See Fortran debugging. You need to submit four Valgrind outputs of errors using 2>, for example, with k=1, 2, 3, 4:

    On Mac:

    valgrind --leak-check=full --dsymutil=yes --track-origins=yes ./yourExecutable_k 2> output_k
    

    On Linux:

    valgrind --leak-check=full --track-origins=yes ./yourExecutable_k 2> output_k
    

    You should check your solution correctness by being able to produce desired results (i.e., three non-empty results and one empty result) from executing:

    grep -in 'f90\|line' output_k