LECTURE NOTES ON Engineering Computing and Technology

lecture notes in engineering and computer science and engineering computing and analysis pdf free download
Dr.JamesSmith Profile Pic
Dr.JamesSmith,France,Professional
Published Date:11-07-2017
Your Website URL(Optional)
Comment
LECTURENOTESON ENGINEERINGCOMPUTING Joseph M. Powers Department of Aerospace and Mechanical Engineering University of Notre Dame Notre Dame, Indiana 46556-5637 USA updated 10 November 2016, 1:05pm2 CC BY-NC-ND. 10 November 2016, J. M. Powers.Contents Preface 7 1 Overview 9 1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.2 A simple program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.2.1 Downloading the program . . . . . . . . . . . . . . . . . . . . . . . . 14 1.2.2 Saving the program onto the AFS server . . . . . . . . . . . . . . . . . 15 1.2.3 Accessing the campus Linux cluster . . . . . . . . . . . . . . . . . . . 15 1.2.4 Compiling a Fortran program . . . . . . . . . . . . . . . . . . . . . . 18 1.2.5 Editing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.3 Speed test: Fortran versus MATLAB . . . . . . . . . . . . . . . . . . . . . . . 20 1.4 Some definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.5 Introduction to engineering plotting with MATLAB . . . . . . . . . . . . . . . 22 1.5.1 A bad MATLAB plot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.5.2 A better MATLAB plot . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 1.5.3 Another bad MATLAB plot . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.5.4 Another better MATLAB plot . . . . . . . . . . . . . . . . . . . . . . . 26 A 1.6 Introduction to LT X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 E 1.7 Introduction to HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.8 UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 1.9 Online compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2 Introduction to problem solving 35 3 Introduction to programming languages 37 4 Introduction to programming 39 4.1 Statement types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.2 Example program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.3 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.4 Another example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 34 CONTENTS 5 Arithmetic 45 5.1 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 5.2 Integer division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 5.3 Binary representation of integers. . . . . . . . . . . . . . . . . . . . . . . . . 48 5.4 Overflow and underflow limits . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.5 Assignment of undefined variables . . . . . . . . . . . . . . . . . . . . . . . . 51 6 Arrays 1 53 6.1 Dimension of an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 6.2 One-dimensional arrays from time series . . . . . . . . . . . . . . . . . . . . 54 6.2.1 Fixed array size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 6.2.2 Variable array size via parameter declaration . . . . . . . . . . . . . 59 6.3 Simple writing to files and MATLAB plotting . . . . . . . . . . . . . . . . . . . 60 7 Arrays 2 63 7.1 Varying the array size at run time . . . . . . . . . . . . . . . . . . . . . . . . 63 7.2 Higher dimension arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 7.3 Two-dimensional arrays of variable size . . . . . . . . . . . . . . . . . . . . . 69 7.4 Non-standard do loop increment syntax . . . . . . . . . . . . . . . . . . . . . 70 8 Whole array features 73 8.1 Dot product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 8.1.1 Real vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 8.1.2 Complex vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 8.2 Matrix transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 8.3 Matrix-vector multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 8.4 Matrix-matrix multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 8.5 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 8.6 Element-by-element matrix “multiplication” . . . . . . . . . . . . . . . . . . 86 9 Output of results 89 9.1 Unformatted printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 9.2 Formatted printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 9.3 Formatted writing to files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 10 Reading data 99 10.1 Unformatted reading from a file . . . . . . . . . . . . . . . . . . . . . . . . . 99 10.2 Formatted reading from a file . . . . . . . . . . . . . . . . . . . . . . . . . . 102 11 I/O Concepts 105 CC BY-NC-ND. 10 November 2016, J. M. Powers.CONTENTS 5 12 Functions 107 12.1 Pre-defined functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 12.2 User-defined functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 12.2.1 Simple structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 12.2.2 Use of dummy variables . . . . . . . . . . . . . . . . . . . . . . . . . 112 12.2.3 Sharing data using module . . . . . . . . . . . . . . . . . . . . . . . . 113 12.2.4 Splitting functions into separate files . . . . . . . . . . . . . . . . . . 115 12.2.5 Creation of executable script files . . . . . . . . . . . . . . . . . . . . 117 13 Control structures 119 14 Characters 127 15 Complex 129 16 Logical 135 17 Introduction to derived types 137 18 An introduction to pointers 139 19 Introduction to subroutines 141 19.1 Simple subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 19.2 Subroutines for solution of a quadratic equation . . . . . . . . . . . . . . . . 143 19.3 Subroutines for solving systems of ordinary differential equations . . . . . . . 145 19.3.1 One linear ordinary differential equation . . . . . . . . . . . . . . . . 146 19.3.2 Three non-linear ordinary differential equations . . . . . . . . . . . . 150 20 Subroutines: 2 161 21 Modules 163 22 Converting from Fortran 77 165 22.1 A hello world program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 22.2 A simple program using arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 166 22.3 A program using subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 23 Python and Fortran 173 24 Introduction to C 175 24.1 A hello world program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 24.2 A program using the Euler method . . . . . . . . . . . . . . . . . . . . . . . 176 CC BY-NC-ND. 10 November 2016, J. M. Powers.6 CONTENTS 25 Introduction to Microsoft Excel 179 25.1 A hello world program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 25.2 A program using the Euler method . . . . . . . . . . . . . . . . . . . . . . . 180 26 Introduction to VBA 183 26.1 A hello world program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 26.2 A program using the Euler method . . . . . . . . . . . . . . . . . . . . . . . 184 26.3 Another VBA Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 26.3.1 Creating a calculation macro . . . . . . . . . . . . . . . . . . . . . . . 187 26.3.2 Clearing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 26.3.2.1 Manual clearing . . . . . . . . . . . . . . . . . . . . . . . . . 190 26.3.2.2 Automated clearing . . . . . . . . . . . . . . . . . . . . . . 191 26.3.3 Automated plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 26.3.4 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 27 Introduction to Mathematica 195 27.1 A hello world program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 27.2 A simple code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 27.3 Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 27.4 Lists, vectors, and matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 27.5 Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 27.6 Some plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 27.7 Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 27.8 The Euler method, DSolve, and NDSolve . . . . . . . . . . . . . . . . . . . . 207 Bibliography 211 Index 213 CC BY-NC-ND. 10 November 2016, J. M. Powers.Preface These are lecture notes for AME 20214, Introduction to Engineering Computing, a one- hour sophomore-level undergraduate course taught in the Department of Aerospace and Mechanical Engineering at the University of Notre Dame. The key objective of the course is to introduce students to the UNIX operating system and structured high performance computing with a compiled language, here chosen to be Fortran 90 and its descendants, as well as some others, such as the interpreted languages MATLAB, Python, Mathematica, VBA, and Microsoft Excel, and a very brief introduction to the compiled language C. Thanks to Mr. Travis Brown for help with a C example program and Ms. Laura Paquin for help with VBA example programs and description. An important secondary objective is to introduce the student to the process of scientific computing: the art of using a computer to solve problems of scientific and engineering rele- vance. Toachieve thatobjective, some attentionis focusedonnumerically solvingphysically motivated systems of ordinary differential equations. The most important of these will be the forced mass-spring-damper system, which will be addressed with a variety of methods. The notes draw often on the text specified for the course, Chivers’ and Sleightholme’s Introduction to Programming with Fortran, Third Edition, Springer, London, 2015. The notes will highlight aspects ofthis text, andaugment it inplaces. The notes and course data can be found at http://www.nd.edu/∼powers/ame.20214. At this stage, anyone is free to make copies for their own use. I would be happy to receive suggestions for improvement. Joseph M. Powers powersnd.edu http://www.nd.edu/∼powers Notre Dame, Indiana; USA = CC BY: 10 November 2016 ThecontentofthisbookislicensedunderCreative Commons Attribution-Noncommercial-No Derivative Works 3.0. 7 \8 CONTENTS CC BY-NC-ND. 10 November 2016, J. M. Powers.Chapter 1 Overview Read C&S, Chapter 1. 1.1 Motivation We are faced with a problem in constrained optimization. We seek to maximize student understanding of • mathematical methods to computationally solve problems arising in aerospace and mechanical engineering, • programminglanguagesforefficientsolutionoflarge-scalemathematicalproblemsaris- ing in engineering, and • operating systems beyond those found by default in consumer-market computers, subject to the constraints • finite time, embodied in the one credit hour allocated to this task, • finite student skills, and • finite instructor skills. We might conjecture that the understanding of these topics, Υ, is a function of the mathe- matical methodμ, the language chosen,λ, the operating system, σ, the pedagogyρ, chosen, the time τ allotted for study, the student and instructor skill sets, κ and κ . In a mathe- 1 2 matically inspired language, we might say Υ =f(μ,λ,σ,ρ,τ,κ ,κ ). (1.1) 1 2 910 CHAPTER 1. OVERVIEW Our constraints are for time τ, student skills κ and instructor skills κ . Our constrained 1 2 optimization problem might be stated as, select μ, λ, σ, and ρ so as to Maximize: Υ = f(μ,λ,σ,ρ,τ,κ ,κ ), (1.2) 1 2 Subject to: τ = 1, (1.3) κ = constant, (1.4) 1 κ = constant. (1.5) 2 We are presented with a wide variety of mathematical problems μ of engineering relevance including • linear systems of algebraic equations, • non-linear systems of algebraic equations, • linear systems of ordinary differential equations, • non-linear systems of differential equations, • partial differential equations, or • optimization problems. We are presented with a wide variety of computing languages to formulate these problems, including • Fortran (from “FORmula TRANslating system”), • COBOL (from “Common Business-Oriented Language”), • ALGOL (from “ALGOrithmic Language”), • Ada, • BASIC (from “Beginner’s All-purpose Symbolic Instruction Code”), • VBA (from “Visual Basic for Applications”), • Pascal, • C, • C++, • C, • Java, CC BY-NC-ND. 10 November 2016, J. M. Powers.1.1. MOTIVATION 11 • MATLAB (from “MATrix LABoratory”), • Mathematica, or • Microsoft Excel. We are presented with a wide variety of operating system environments in which to execute our programs including • Microsoft Windows, • DOS, • OS-X, • UNIX, or • Linux. Following considerable consideration, coupled with some experimentation, we believe the near-optimal solution, reflecting the severe constraint of τ = 1 credit hour is given by the following: student understanding, Υ, of engineering mathematics, relevant languages, and advanced operating systems is given by choosing • λ = Fortran 2003, • σ = Linux. Near neighbors within the solution space are also perfectly acceptable, e.g. Fortran 90, Fortran 95, Fortran 2008, UNIX, OS-X. If the constraints of the curriculum evolve, and languages and operating systems evolve, the optimal solution may evolve All choices have advantages and disadvantages. Certainly one chooses modes of trans- portation depending on a variety of needs. We depict rough and imperfect analogies be- 1 tween some modern transportation choices and modern computing languages in Fig. 1.1. For transportation purposes, one might imagine that • The racing cycle has speed, power, and agility but requires a highly trained user to achieve peak performance. It maps into C. • The modern muscle car has all features expected by most mass-market drivers, draws heavily on past experiences, but still may not be the right machine for all market segments. It maps into Fortran. 1 images from http://motorsportsnewswire.files.wordpress.com/2011/05/infineon 2011 brammo empulse rr.jpg http://www.netcarshow.com/ford/2013-mustang boss 302/1600x1200/wallpaper 01.htm http://www.carwallpapers.cc/wp/dodge/grand-caravan/2011/Dodge-Grand-Caravan-2011-1600x900-010.jpg http://www.motorzoeker.nl/public/motorfotos/large/vespa/5611 foto1 k25j3xt2j8.jpg https://commons.wikimedia.org/wiki/File:Campagna T-Rex 14-R rear left.jpg CC BY-NC-ND. 10 November 2016, J. M. Powers.12 CHAPTER 1. OVERVIEW high performance 1960’s inspired modern racing cycle: C? muscle car: Fortran? well-engineered and versatile lightweight and practical unconventional but stable family minivan: MATLAB? scooter: Excel? motorized reverse tricycle: VBA? Figure 1.1: Loose transportation analogies with computing languages. • The minivan is appropriate for a wide variety of drivers and passengers, is durable, and optimized for safety; it will not compete well in a race. It maps into MATLAB. • The scooter is affordable, maneuverable, and is appropriate for many urban environ- ments; it is not right for the highway. It maps into Excel. • The motorized reverse tricycle is stable for some highway use, but unconventional. It maps into VBA. Now focusing on our actual computing systems, we list some advantages and disadvan- tages associated with our present choices. First for Fortran: • Fortran advantages – a compiled languagewhich yields very fast binary executable code widely used for large scale problems in computational science, e.g. the widely used Top 500 su- percomputing benchmark problem is based on Fortran-implemented algorithms. – used in many modern supercomputing applications, e.g. the Department of En- ergy’s major initiative in scientific computing for the 21st century, Predictive Science Academic Alliance Program (PSAAP), – explicitly designed for mathematical problems common in engineering; pedagog- ically straightforward implementation of standard notions such as sine, cosine, exponential, vectors, and matrices, – widely used for decades in engineering with a large data base of legacy code and 2 packaged software, 2 see http://www.netlib.org/ CC BY-NC-ND. 10 November 2016, J. M. Powers.1.1. MOTIVATION 13 – another language in the engineer’s multi-lingual arsenal for problem-solving, – alanguagewhich opensthedoortolearningawidevariety ofcompiledlanguages, such as C, which was designed for device drivers and operating systems (not sci- entific computing), and – forces care and precision to be used in code writing–thus reinforcing fundamental engineering design principles for quality control which transcend programming. • Fortran disadvantages – forces care and precision to be used in code writing–which induces frustration when the code fails to work properly, – relative to some other languages, does not interact as easily with the operating system and input/output data, thus preventing use in many hardware applica- tions, e.g. robotics, – no longercommonly used inthe computer science community, especially the large fractionofthatcommunity whonolongerareconcerned withscientific computing of mathematics-based engineering problems based on differential equations, and – not particularly relevant to the large user community who primarily run pre- programmed specialty software packages for engineering analysis and design, but do not generate original source code. For Linux, we have • Linux advantages – widely used, – allows user to more easily understand computer system architecture, – freely available – very similar to UNIX and OS-X. • Linux disadvantages – more effort to learn, relative to What-You-See-Is-What-You-Get (WYSIWYG) systems such as Windows or the front end of OS-X. – users must manage their own systems. Whatever language and operating system we use, and this course will consider Fortran withshortexcursionsintoC,MATLAB,Microsoft Excel, VBA,andMathematica, theessential job of nearly any programming language is executing so-called three R’s: • Readin’ • ’Ritin’ CC BY-NC-ND. 10 November 2016, J. M. Powers.14 CHAPTER 1. OVERVIEW • ‘Rithmatic A typical program will change the order (and we will now use proper spelling) and first • Read input data from a file or the screen, • Perform arithmetic operations on the data, and • Write output data to a file or the screen. Recognizing the various methods that various languages use to execute the three R’s is the key to learning a new computer language. There are a small number of typical operations in scientific computing. Once the student learns how to do an operation in one language, it is much easier to translate these steps to any of the other languages. Thus, in some sense, learningacomputerlanguagemaybemoreimportantthanlearninganyparticularcomputer language. That is because learning a language typically entails learning the more complex generalities associated with all languages. 1.2 A simple program Let us consider one of the simplest possible Fortran that one can imagine, a so-called “hello world” program. 1.2.1 Downloading the program The program, with file name helloworld.f90, is given here: program test print,’hello world’ end program test One can download this program from the web by clicking the following web link, http://www.nd.edu/∼powers/ame.20214/2e/helloworld.f90 The first line of the program is the program name, where the name is arbitrary. The second line tells the program to print to the screen, indicated by a ∗, the words within the single quotation marks. The program is ended by a program end statement. The file name which ends in “.f90” is essential and tells the compiler that this file follows the syntax of Fortran 90 and beyond, beyond including Fortran 90, 95, 2003, and 2008. It should be noted that our local system can in fact invoke the Fortran 2003 standard, but for nearly all problems we will consider, the Fortran 90 standard will suffice. CC BY-NC-ND. 10 November 2016, J. M. Powers.1.2. A SIMPLE PROGRAM 15 1.2.2 Saving the program onto the AFS server After downloading, one should save the file onto the campus file server known as AFS and choose to name the saved file as helloworld.f90. The letters AFS are an acronym for “Andrew File System.” Files saved onto your AFS space can be accessed and edited from a wide variety of campus and off-campus machines. In many ways storing files on AFS is like storing them on the “cloud,” though AFS has a much longer history than the cloud. Importantly, it is possible to compile and execute binary executable files from AFS. There are a variety of ways to save the file. Most browsers have some variety of save as option. If exercised, be sure to save the file as plain text with a .f90 extension in its name. Or one can cut and paste the necessary text into a variety of text editors such as gedit, described in more detail in Sec. 1.2.5. Note that the AFS space is distinct from the more common campus space in netfile. For purposes of running compiled programs which are binary executable, such as those originating in Fortran or C source codes, netfile is completely unusable. In short, while you could certainly save a text file within netfile, you could never compile or execute the program. 1.2.3 Accessing the campus Linux cluster To compile and execute the program, you will need to log onto a machine which has a Fortran compiler. It is strongly recommended to directly log in by actually sitting at a campus Linux cluster machine when first learning the Linux operating system. Indeed, every- thing that can be achieved sitting in front of the Linux machine can also be achieved remotely via a laptop; however, many things can go wrong. After brief experience in front of the actual machine, it is not a difficult step to use Linux remotely from a laptop. That said, many users do have sufficient experience to go directly to remote login from a laptop, and that procedure is described here. One important machine for remote login is the campus Linux machine darrow.cc.nd.edu. The machine darrow is useful because all campus personnel can log in to it from any remote site, on or off campus. Here is what one might doiflogginginfromthe Terminal application ofapersonal Macintosh machine using the so-called “secure shell” program ssh: esc300037: powers ssh -X darrow.cc.nd.edu -l powers powersdarrow.cc.nd.edu’s password: Last login: Wed Aug 10 11:16:28 2016 from esc300037.esc.nd.edu darrow patching and reboot: Thursday, August 11, 2016, 8:00 pm to 9:30 pm. Please plan accordingly. CC BY-NC-ND. 10 November 2016, J. M. Powers.16 CHAPTER 1. OVERVIEW powersdarrow5 Here, the argument of the −l option is your netid. Mine is powers. The general form is ssh -X darrow.cc.nd.edu -l netid If darrow.cc.nd.edu is overloaded with too many users, a user may log in remotely to any of a set of virtual Linux machines. Their names are remote101.helios.nd.edu remote102.helios.nd.edu remote103.helios.nd.edu remote104.helios.nd.edu remote105.helios.nd.edu remote106.helios.nd.edu remote107.helios.nd.edu remote108.helios.nd.edu remote201.helios.nd.edu remote202.helios.nd.edu remote203.helios.nd.edu remote204.helios.nd.edu remote205.helios.nd.edu remote206.helios.nd.edu remote207.helios.nd.edu remote208.helios.nd.edu For example to log in remotely to one of the virtual Linux machines, one might execute the command sequence esc300037: powers ssh -X remote103.helios.nd.edu -l powers The authenticity of host ’remote103.helios.nd.edu (129.74.50.104)’ can’t be established. RSA key fingerprint is 80:12:f5:2e:91:c7:97:83:8b:54:6a:2d:10:14:6f:e2. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ’remote103.helios.nd.edu,129.74.50.104’ (RSA) to the list of This system is for the use of AUTHORIZED USERS ONLY. CC BY-NC-ND. 10 November 2016, J. M. Powers.1.2. A SIMPLE PROGRAM 17 Anyone using this system expressly consents to such monitoring and is advised that if such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to law enforcement officials. See the University of Notre Dame Responsible Use Policy for information regarding proper use of this machine (http://oit.nd.edu/policies). Remote use of this system is not for running big processes. If you need to run big processes for research, please get an account from Center of Research Computing (http://crc.nd.edu). Please email helpesc.nd.edu for any question of suggestion. powersremote103.helios.nd.edu’s password: Last login: Thu Nov 12 15:20:01 2015 from dbrt155l-00.cc.nd.edu powersremote103 Other campus Linux machines are useful as well, but the user must be sitting at the machine. A practical advantage of these physical machines is they only allow a single user, so they will not become overloaded. Several such Linux machines can be found in • 149 Fitzpatrick Hall (Engineering Library), • 303 Cushing Hall, and • 108-110, 212-213 Stinson-Remick Hall. A list of available machine names and locations is found at http://pug.helios.nd.edu:2080/clusterfree.html For students with Macintosh laptops, one can download so-called X11, also known as XQuartz, software to create an X Windows environment. One can try the following site for download: http://www.xquartz.org Once downloaded, take care to open the terminal application from XQuartz rather than the standard Macintosh terminal application. From the XQuartz terminal, one can invoke the command ssh command to a Linux machine Some more information can be found at http://en.wikipedia.org/wiki/XQuartz CC BY-NC-ND. 10 November 2016, J. M. Powers.18 CHAPTER 1. OVERVIEW For students with Windows laptops, one can download software to create an X Windows terminal environment. Instructions can be found at http://www.nd.edu/∼powers/ame.20214/xming.pdf When invoking the so-called xming software, be sure to examine the “Connection” menu on the left and under SSH, X11, check enable X11 forwarding. Another common way, which requires a little more effort, to bring UNIX functionality into a Windows environment is to install the free, open-source UNIX-emulator, Cygwin, onto a Windows machine. https://www.cygwin.com 1.2.4 Compiling a Fortran program On darrow.cc.nd.edu, the relevant virtual Linux machines, and all physical campus Linux cluster machines reside the Fortran compilers • ifort, and • gfortran. The compiler ifort is the so-called Intel Fortran compiler. The compiler gfortran is an open source compiler. The ifort compiler works on most campus Linux machines, but may not work for all on darrow.cc.nd.edu. The gfortran compiler should work on all campus Linux machines. Focus here will be on the ifort compiler; though it is a useful exercise tomake sure your programcompiles and executes onavariety ofcompilers, asthere can be subtle differences. All these compilers work in essentially the same way. For instance to use ifort to compile helloworld.f90, we perform powersremote101 ame.20214 ifort helloworld.f90 This generates a so-called “binary” executable file, which is not easily viewable, named “a.out”. We execute the file a.out via the command and get powersremote101 ame.20214 a.out hello world. powersremote101 ame.20214 The outputofthe programisprinted tothescreen. Though itisnotatallimportantforthis problem, we actually compiled the program with a Fortran 90 compiler. We can compile and execute the program in Fortran 2003 via the command sequence powersremote101 ame.20214 ifort helloworld.f90 -stand f03 powersremote101 ame.20214 a.out hello world. powersremote101 ame.20214 CC BY-NC-ND. 10 November 2016, J. M. Powers.1.2. A SIMPLE PROGRAM 19 Here,theso-calledcompileroption, -stand f03,enforcedthecompilationusingtheFortran 2003 standard. We can compile and execute the program with the gfortran compiler via the command sequence powersdarrow1-p gfortran helloworld.f90 powersdarrow1-p a.out hello world powersdarrow1-p 1.2.5 Editing text You will need to be able to edit text files. This is best achieved with a text editor. For the relevant tasks, tools such as Microsoft Word are inappropriate, because they generally do not format the files in plain text; instead they often add extraneous data to the files for purposes of visual display. These visually appealing elements render the files unusable for programming purposes. Instead, you should employ any of a variety of standard text editors. Perhaps the most straightforwardisoneknownasgedit. Itisavailableonthecampus Linuxclustermachines. To edit the file helloworld.f90, one can invoke on a campus Linux cluster machine the command powersdarrow1-p gedit helloworld.f90 & This command spawns a new window in which the file helloworld.f90 can be edited and saved. The character & is a useful UNIX command which commands the system to allow the terminal window to be used simultaneously with the program gedit. If one is using gedit from a remote terminal or personal laptop machine, one must be sure to have logged in from a so-called X terminal window, using the command ssh -X darrow.cc.nd.edu -l userid in order for the edit window to display. This is straightforward on a Macintosh computer through use of its terminal application found in the Utilities folder. On a Windows laptop, one may wish to use the terminal available via the Cygwin package. This is not an issue if the user is seated at the actual machine in use. An incomplete list of common text editors available on the campus Linux cluster, each with advantages and disadvantages is as follows: • gedit • Kate, invoked by kate on the Notre Dame cluster (but not on darrow) • vi • Emacs, invoked by emacs on the Notre Dame cluster. One canalso use ordinary texteditors on personalcomputing machines andsave the file asa plaintext fileintheappropriatespace. Notethatoneshould notsave a Fortran source code file in the common “rich text format” (.rtf) and expect it to be able to compile correctly. CC BY-NC-ND. 10 November 2016, J. M. Powers.20 CHAPTER 1. OVERVIEW 1.3 Speed test: Fortran versus MATLAB Let us check the speed of an ordinary Fortran program versus its MATLAB equivalent. Speed tests are notorious for being unfair, depending on the options exercised. In this case, we will use options which are widely considered to be default for both programs, and we will execute on the same machine. Both programs will initialize a large matrix, of dimension n×n. We will call the matrix x and its elements will be denoted x . We will initialize so ij that each element takes on the value of the product of i and j: x =ij, where i =1,...,n, ij and j = 1,...,n. Thus x = (1)(1) = 1, x = (1)(2) = 2, ..., x = (2)(5) = 10, and so 11 12 25 on. If n =5, we should thus form the matrix     (1)(1) (1)(2) (1)(3) (1)(4) (1)(5) 1 2 3 4 5     (2)(1) (2)(2) (2)(3) (2)(4) (2)(5) 2 4 6 8 10         x = (3)(1) (3)(2) (3)(3) (3)(4) (3)(5) = 3 6 9 12 15 . (1.6)         (4)(1) (4)(2) (4)(3) (4)(4) (4)(5) 4 8 12 16 20 (5)(1) (5)(2) (5)(3) (5)(4) (5)(5) 5 10 15 20 25 When n is large, it will take a long time to execute the initialization. Let us perform this process via Fortran and MATLAB on the linux machine, darrow.cc.nd.edu. We shall take n = 5000, a modestly sized matrix for scientific computing. The Fortran program matrix.f90 and its execution are as follows: powersdarrow1-p ame.20214 cat matrix.f90 program matrix beginning of the program implicit none force all variables to be declared integer :: i,j declare i and j to be integers integer, parameter :: n = 5103 give the dimension of the matrix real :: x(n,n) declare the matrix x to be n x n and real do i=1,n first do loop do j=1,n second do loop x(i,j) = real(i)real(j) initialize the matrix enddo end of do second loop enddo end of first do loop print,n,x(n,n) print some values end program matrix end of program powersdarrow1-p ame.20214 ifort matrix.f90 powersdarrow1-p ame.20214 a.out 6000 3.6000000E+07 powersdarrow1-p ame.20214 We shall worry about the details of the program later. Note for now that there are many complexities to execute this seemingly simple task. This is typical of Fortran codes. We can check the speed of the program by executing with a UNIX utility time. We find CC BY-NC-ND. 10 November 2016, J. M. Powers.

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.