Writing your own Madagascar applications Sergey Fomel University of Texas at Austin August 30, 2006...

18
Writing your own Madagascar applications Sergey Fomel University of Texas at Austin August 30, 2006 Vancouver, BC

Transcript of Writing your own Madagascar applications Sergey Fomel University of Texas at Austin August 30, 2006...

Writing your ownMadagascar applications

Sergey FomelUniversity of Texas at Austin

August 30, 2006Vancouver, BC

August 30, 2006 Vancouver School & Workshop 2 of 17

This Presentation How to add your own low-level programs

• Programming in C

• Programming in other languages• C++, Fortran-77, Fortran-90, Python, MATLAB

How to contribute your programs, tests, and texts• Who should contribute and why

• Copyright and licensing Resources

• http://rsf.sourceforge.net/wiki/index.php/API

• http://rsf.sourceforge.net/wiki/index.php/Demo

• http://rsf.sourceforge.net/wiki/index.php/Adding

August 30, 2006 Vancouver School & Workshop 3 of 17

The Easiest Way to Add Programs to Madagascar

Create a directory under TOPDIR/user Follow examples from other directories cd TOPDIR/user; scons

• compiles locally with debugging flags

cd TOPDIR; scons install• compiles globally with optimization flags

• installs under $RSFROOT

August 30, 2006 Vancouver School & Workshop 4 of 17

Leaky Integration: leakint.c

void leakint (int nt /* trace length */, float rho /* leakage */,

float *trace /* integrated trace */)/*< leaky integration >*/{ int it; for (it=1; it < nt; it++) /* integrate */ trace[it] += rho*trace[it-1]; }

comment the interface

special style comment to generate leakint.h

scons

• generates leakint.h

• compiles leakint.o

August 30, 2006 Vancouver School & Workshop 5 of 17

Leaky Integration: Mleakint.c /* Leaky integration. */#include <rsf.h>#include “leakint.h”

int main(int argc, char* argv[]){ int n1, n2, i2; float rho, *pp; sf_file in, out;

sf_init(argc,argv);

in = sf_input("in"); out = sf_output("out");

if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(in,1);

short descriptionmain librarylocal subroutine

initialize command line

special type for files

standard input/output

trace lengthnumber of traces

August 30, 2006 Vancouver School & Workshop 6 of 17

Leaky Integration: Mleakint.c

if (!sf_getfloat(“rho”,&rho)) rho=1.; /* leakage */

pp = sf_floatalloc(n1);

/* loop over traces */ for (i2=0; i2 < n2; i2++) { sf_floatread(pp,n1,in); leakint (n1,rho,pp); sf_floatwrite(pp,n1,out); }

exit(0);}

read parameter from command lineadd comment for self-documentation

error-checking memory allocation

read trace

write trace

scons

• compiles sfleakint

August 30, 2006 Vancouver School & Workshop 7 of 17

Leaky Integration: leakint.f90

module leakintcontains subroutine leakint (rho,trace) ! leaky integration float, intent (in) :: rho ! leakage float, dimension (:) :: trace ! Integrated trace int :: it, nt

nt = size(trace) do it=2, nt ! integrate trace(it) = trace(it) + rho*trace(it-1) end do end subroutineend module

comment the interface

scons

• generates leakint.mod

• compiles leakint.o

August 30, 2006 Vancouver School & Workshop 8 of 17

Causal integration: Mleakint.f90! Leaky integration.program Mleakint use rsf use leakint

implicit none integer :: n1, n2, i2 real, dimension (:), allocatable :: trace type (file) :: in, out

call sf_init()

in = rsf_input() out = rsf_output()

call from_par(in,"n1",n1) n2 = filesize(in,1)

short description

main modulelocal module

initialize command line

special type for files

standard input/output

trace lengthnumber of traces

August 30, 2006 Vancouver School & Workshop 9 of 17

Leaky Integration: Mleakint.f90

call get_par(“rho”,rho,1.) ! leakage

allocate (trace (n1))

! loop over traces do i2=1, n2 call rsf_read(in,trace) call leakint (rho,trace) call rsf_write(out,trace) end do

end program Mleakint

read parameter from command line

read trace

write trace

scons

• compiles sfleakint

August 30, 2006 Vancouver School & Workshop 10 of 17

Other Language Bindings

C++ Fortran-77 Python MATLAB … http://rsf.sourceforge.net/wiki/index.php/API http://rsf.sourceforge.net/wiki/index.php/Demo

August 30, 2006 Vancouver School & Workshop 11 of 17

This Presentation How to add your own programs

Programming in CProgramming in other languages

C++, Fortran-77, Fortran-90, Python, MATLAB How to contribute your programs, tests, and texts

• Who should contribute and why

• Copyright and licensing Resources

• http://rsf.sourceforge.net/wiki/index.php/API

• http://rsf.sourceforge.net/wiki/index.php/Demo

• http://rsf.sourceforge.net/wiki/index.php/Adding

August 30, 2006 Vancouver School & Workshop 12 of 17

Four Reasons to Contribute to Open Source / Free Software

To help your neighbor To show your talents To enable scientific progress To improve software quality

August 30, 2006 Vancouver School & Workshop 13 of 17

Four Reasons to Contribute to Open Source / Free Software I

To help your neighbor• “Run a program as you wish, for any purpose you wish, not limited

to any narrowly defined application.”

• “Help yourself by improving the program (which requires access to source code).”

• “Help your neighbor by sharing a copy of the program with them.”

• “Help community by sharing the improved copy at large.”

To show your talents To enable scientific progress To improve software quality

Ric

hard

Sta

llman

August 30, 2006 Vancouver School & Workshop 14 of 17

Four Reasons to Contribute to Open Source / Free Software II

To help your neighbor To show your talents

• “Open source is a gift to those who need to hire technical people. With open source, you can track someone’s work and contributions – good and bad – over a lengthy period of time.”

• “The top software developers are more productive than average software developers not by a factor of 10x or 100x or even 1000x but by 10,000x.” -- Nathan Myhrvold as quoted by Stephen Covey

To enable scientific progress To improve software quality

37si

gnal

sM

icro

soft

August 30, 2006 Vancouver School & Workshop 15 of 17

Four Reasons to Contribute to Open Source / Free Software III

To help your neighbor To show your talents To enable scientific progress

• “Within the world of science, computation is now rightly seen as a third vertex of a triangle complementing experiment and theory. However, as it is now often practiced, one can make a good case that computing is the last refuge of the scientific scoundrel.”

To improve software quality

R.

LeV

eque

August 30, 2006 Vancouver School & Workshop 16 of 17

Four Reasons to Contribute to Open Source / Free Software IV

To help your neighbor To show your talents To enable scientific progress To improve software quality

• “Given a large enough beta-tester and co-developer base, almost every problem will be characterized quickly and the fix obvious to someone.”

• "Given enough eyeballs, all bugs are shallow."

Eric

Ray

mon

d

Firefox

IE

Safari

Other

August 30, 2006 Vancouver School & Workshop 17 of 17

How to contribute Get a permission to distribute under GPL

• “Using the GNU GPL will require that all the released improved versions be free software. This means you can avoid the risk of having to compete with a proprietary modified version of your own work.”

• Add GPL notice to all files.• Keep your ©

Register at SourceForge and send us your login name to be added to the developer list

Commit your files and directories to the repository using svn add and svn commit.

August 30, 2006 Vancouver School & Workshop 18 of 17

Lessons

Adding your own programs is easy• Pick language of your choice

• C, C++, Fortran-77, Fortran-90, Python, MATLAB

• Follow examples and conventions

• Test Contributing your programs and tests is easy

• Get permission if you need it

• Honor GPL

• Adopt Subversion