Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

Adding Rappture to MATLAB Applications
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
1 What’s Under the Hood? Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
Using workspaces on nanoHUB.org Michael McLennan Software Architect Network for Computational Nanotechnology.
1 Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative Commons.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Lecture 2: OS Programming Interface T.Yang, CS
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Exercise 10 Review: pointers, strings and recursion.
1 Using Workspaces to Develop Simulation Tools Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
A brief [f]lex tutorial Saumya Debray The University of Arizona Tucson, AZ
1 More Rappture Objects Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative Commons See.
CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options.
Initialization of Clang
University of Calgary – CPSC 441. C PROGRAM  Collection of functions  One function “main()” is called by the operating system as the starting function.
1 More Rappture Objects Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Text Processing. Outline Announcements: –Homework I: due Today. by 5, by Discuss on Friday. –Homework II: on web HW I: question 7 Finish functions.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
MaterialsHub - A hub for computational materials science and tools.  MaterialsHub aims to provide an online platform for computational materials science.
Regression Testing Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
OpenSees on NEEShub Frank McKenna UC Berkeley. Bell’s Law Bell's Law of Computer Class formation was discovered about It states that technology.
1 Advanced Visualization Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
Week 2 - Friday.  What did we talk about last time?  Base systems  C literals  Representations in memory.
Advanced Rappture Concepts and Tips Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Introducing the Rappture Toolkit Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
1 Introducing the Rappture Toolkit Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative.
What’s Under the Hood? Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
C. C ? K & R C – The Kernighan and Richie classic ANCI C -- started 1983 – ANSI X and ISO/IEC 9899:1990 – Standard C, C89, C90 C90 –
Using Simulation Workspaces Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University 1 This work licensed under Creative Commons.
1 Introducing the Rappture Toolkit Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration This work licensed under Creative.
CSCI 330 UNIX and Network Programming
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
Chapter Ten Developing UNIX Applications In C and C++
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
1 Regression Testing Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
Week 4 – Functions Coding Functions. Purpose of Coding Functions A function is written to perform a well-defined task; rather than having all logic in.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
Using Subversion for Source Code Control Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Rappture with Fortran Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license.
Lecture 3: Getting Started & Input / Output (I/O)
A bit of C programming Lecture 3 Uli Raich.
Characters and Strings
Command Line Arguments
Command line arguments
MaterialsHub - A hub for computational materials science and tools.
CS 201 A Whirlwind Tour of C Programming
הרצאה 08 פרמטרים ל- main קרן כליף.
Microsoft DirectShow.
Program Control Structures
GNU gcov (1/4) [from Wikipedia]
The Designer.
sscanf()- string scan function
Govt. Polytechnic,Dhangar
GNU gcov (1/4) [from Wikipedia]
Appendix F C Programming Environment on UNIX Systems
Characters and Strings
ENERGY 211 / CME 211 Lecture 28 December 1, 2008.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
SPL – PS1 Introduction to C++.
Presentation transcript:

Rappture with C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration

tool.xml Example: app-fermi executable Rappture GUI Press Simulate to … … Press Simulate to … … See example codeexample code

tool.xml Example: app-fermi Rappture GUI executable #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; }

#include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } Starting Point fermi.c (simulator written in C) Input Output Physics

#include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; printf("Enter the Fermi energy in eV:\n"); scanf("%lg", &Ef); printf("Enter the Temperature in K:\n"); scanf("%lg", &T); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); printf("%f %f\n",f, E); E = E + dE; } return 0; } Starting Point fermi.c (simulator written in C) Input Output Physics

Rappture Inputs fermi.c (simulator written in C) #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … #include "rappture.h" #include int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; int err; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); rpGetString(lib,"input.(temperature).current",&data); T = rpConvertDbl(data, "K", &err); rpGetString(lib,"input.(Ef).current",&data); Ef = rpConvertDbl(data, "eV", &err); kT = e-5 * T; Emin = Ef - 10*kT; Emax = Ef + 10*kT; … “72F” “2.4eV” 2.4

Rappture Outputs fermi.c (simulator written in C) … E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); sprintf(line,"%f %f\n",f, E); rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND); E = E + dE; } rpResult(lib); return 0; } … E = Emin; dE = 0.005*(Emax-Emin); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); sprintf(line,"%f %f\n",f, E); rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND); E = E + dE; } rpResult(lib); return 0; } “x y \n”

Compiling the Rappturized Code From your workspace on nanoHUB... % cd tooldir % ls tool.xml fermi.c % gcc -g fermi.c –o fermi –I/apps/rappture/current/include –L/apps/rappture/current/lib –lrappture -lm % ls tool.xml fermi.c fermi % rappture % cd tooldir % ls tool.xml fermi.c % gcc -g fermi.c –o fermi –I/apps/rappture/current/include –L/apps/rappture/current/lib –lrappture -lm % ls tool.xml fermi.c fermi % rappture

How does the program get invoked? tool.xml Press Simulate to … … Press Simulate to … … Replaced with name of driver file Ex: driver327.xml Replaced with directory containing tool.xml file Ex: /apps/yourtool/current Invoke the C program… …with the driver file as the first argument

How does the program get /apps/yourtool/current/fermi driver327.xml #include "rappture.h" … int main(int argc, char *argv[]) { double T, Ef, E, dE, kT, Emin, Emax, f; RpLibrary *lib; const char* data; lib = rpLibrary(argv[1]); … rpResult(lib); return 0; }

Not Much Overhead It’s easy to add Rappture to your new tools: Fermi Level eV 0eV Fermi Level eV 0eV Instead of this…Do this… Documentation scanf("%lg",&Ef); rpGetString(lib, path, &data); Ef = rpConvertDbl(data, “eV", &err); rpGetString(lib, path, &data); Ef = rpConvertDbl(data, “eV", &err); printf(“%g”,Ef); rpPutString(lib, path, val, RPLIB_APPEND); … rpResult(lib); rpPutString(lib, path, val, RPLIB_APPEND); … rpResult(lib);

tool.xml Example: app-fermi Rappture GUI executable program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi

Starting Point fermi.f (simulator written in Fortran) program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi Input Output Physics

Starting Point fermi.f (simulator written in Fortran) program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi program fermi read(5,*) Ef read(5,*) T kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(6,*) f, E 10 continue end program fermi Input Output Physics

Rappture Inputs fermi.f (simulator written in Fortran) program fermi … call getarg(1,inFile) driver = rp_lib(inFile) call rp_lib_get(driver, + "input.number(temperature).current“, str) okay = rp_units_convert_dbl(str, “K”, T) call rp_lib_get(driver, + "input.number(Ef).current“, str) okay = rp_units_convert_dbl(str, “eV”, Ef) kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) … program fermi … call getarg(1,inFile) driver = rp_lib(inFile) call rp_lib_get(driver, + "input.number(temperature).current“, str) okay = rp_units_convert_dbl(str, “K”, T) call rp_lib_get(driver, + "input.number(Ef).current“, str) okay = rp_units_convert_dbl(str, “eV”, Ef) kT = e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT dE = 0.005*(Emax - Emin) … “72F” “2.4eV” 2.4

Rappture Outputs fermi.f (simulator written in Fortran) … dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(xy,'(E20.12, F13.9, A)') f, E, char(10) call rp_lib_put_str(driver, + "output.curve(f12).component.xy", xy, 1) 10 continue call rp_result(driver) end program fermi … dE = 0.005*(Emax - Emin) do 10 E=Emin,Emax,dE f = 1.0/(1.0+exp((E-Ef)/kT)) write(xy,'(E20.12, F13.9, A)') f, E, char(10) call rp_lib_put_str(driver, + "output.curve(f12).component.xy", xy, 1) 10 continue call rp_result(driver) end program fermi “x y \n”

Compiling the Rappturized Code From your workspace on nanoHUB... % cd tooldir % ls tool.xml fermi.f % g77 -g fermi.f –o fermi –L/apps/rappture/current/lib –lrappture % ls tool.xml fermi.f fermi % rappture % cd tooldir % ls tool.xml fermi.f % g77 -g fermi.f –o fermi –L/apps/rappture/current/lib –lrappture % ls tool.xml fermi.f fermi % rappture

How does the program get invoked? tool.xml Press Simulate to … … Press Simulate to … … Replaced with name of driver file Ex: driver327.xml Replaced with directory containing tool.xml file Ex: /apps/yourtool/current Invoke the Fortran program… …with the driver file as the first argument

How does the program get /apps/yourtool/current/fermi driver327.xml program fermi … call getarg(1,inFile) driver = rp_lib(inFile) call rp_lib_get(driver, + "input.number(temperature).current“, str) … call rp_result(driver) end program fermi

Not Much Overhead It’s easy to add Rappture to your new tools: Fermi Level eV 0eV Fermi Level eV 0eV Instead of this…Do this… Documentation read(5,*) Ef call rp_lib_get(driver, path, str) ok = rp_units_convert_dbl(str, “eV”, Ef) call rp_lib_get(driver, path, str) ok = rp_units_convert_dbl(str, “eV”, Ef) write(6,*) Ef call rp_lib_put_str(driver, path, val, 0) … rp_result(driver) call rp_lib_put_str(driver, path, val, 0) … rp_result(driver)

Reference Documentation Documentation Rappture-C/C++ API Rappture-Fortran API Examples: app-fermi in C app-fermi in Fortran