Parallel Programming CS 475
Popular in Course
Popular in ComputerScienence
This 18 page Class Notes was uploaded by Betty Kertzmann on Tuesday September 22, 2015. The Class Notes belongs to CS 475 at Colorado State University taught by Staff in Fall. Since its upload, it has received 9 views. For similar materials see /class/210189/cs-475-colorado-state-university in ComputerScienence at Colorado State University.
Reviews for Parallel Programming
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 09/22/15
szuahze Wm datawnh nglm t1pwww1h39n camMewapexwaxkshbnzyquwlm Visualize your data with gnuplot Meshes graphs and Marple masses at mquot senses Level Intruductury Nxshznth Sas mshanth sasng sxbm eum StaffSu tvme Engneer IBM 22 Jul ZUEI4 Tum yuur data and funmuns mm pmfessmnalrluukmg gaphs wnh GnupluM u a eely msmbmea nV Mu V Vth am Lhs tuul effeeuvely w w PrV lw Humming sz wnh thhm a m an xnta39amve sessmn six menms later suppm nrdxffermt tenmnals creating vanznts Le 1989 and 199m these were mergedmm angle 2 n Andm Apnl zunA here shuuld apply m uLha39 versmns as well Wham pussxble 1 Wm mmhun me mzjur dx erences The uf mal Web sue fur 3mm s lmed m Resuurces In the fulluwmg M NH m We cun ne uurselves m ZD plats smee they are he must cummun O mhm and M NH m n F r wn me cummand but 1 am talk abuut n The basics sxgq gt r r Example yuu can 1am 2151nn7nzn AM Visualize 3mm dauwnh gnuplr znflx mp www 1bm cnmdevelnperwmkslxbnxylgunpan me mputpmmpt butthe defaults functmn 51mlaxly The r ltcommandgt andme cummands help set yrange and help secmwmseqmqmmehelpa eeaehmmmand Nance f In PUPYZ undastand huwm use a cummand the mstall Cd quates andtypem load 39alldem39 Indmdual dem lesmLhsdnecturydemunsmtemmvxdual funchnnsand m u h that we can gl stmad WALth further adv Altmatwely savethewhulehshngmm atempmary le andrumtby typmg load 39fllename39 anhe gnupm pmmpt dam fmg me quates ThecummandfmZDplutsxspredmtably plot Typem plot 51nx atmepmmpt yuushumdseethefarmhax sme curve m a pnprup wmduw Figure 1 gum 4 m en mm 41545359 5 u 5 m Mu a wewant m m nm d Mathanatmans kaths as the mtatmn fm surcalled clused mmvals Has we use rpl m m gl me smusmd cycle Listing 1 5mm frnmrpi m pi SEE xrange 4mm replu 8152007 11 30 AM Visualize ym datawnh gunpm mp www xbm mmmmnpexwmksubmyquuplw reset Figure 2 Rzplntting the sine gzph y mi 3 2 4 n 2 a mua ILsauzz mm W H mm Trytypmgm replut cusx Syntamcallythxsxs equivalemtu plot 51nx cusx Replut Thus 51nXx Figure 3 s39n30x 3 mm 2151007 11 30 AM up www mm camMewapexwmkshbnzyLgiwlm visuiim wur emumi guinm 4am x minK 03 n5 in in n 02 N m 5 u 5 m 41119741 mm quota y n besst Whmh Expunmhanun Kinseam Lhapuweryis cunvemmdy wnttEn as x y Nam let us gve miss m the graph My First Graph and the axes mm is angig in degrees and yams is sm2ngle Listing 2 Giving titles in the mph and 2x2 Set my rst graph Set magi Angie n in ames Set y abe SV KBNZ EJ um moo h w r duuble quated smngs Winduwsusersbevmre Ifyuutmdtu use duuble quated smngs fur Slenzmes yuu Win havetu quotc develuperwurks v intranmts in ma in n4 4i i i F M wh quotlabelquotmquutes g ltDpt10nalilevelgt Linings Aiming the tics an the 2x2 and sa ngz girl as D x WE want an y ans CyUE u an piz ran rmz w i mo 1 auxmm ii an AM szuahze wur datawnh nglm 5am up www 1m camMewaperwmkshbnzyquwlm Z39p 1 pm 1 Set and Set mm AHE EVV m qurees Set mew sm a q el um moo Figure 4 s39n30 wiLh u39es u39ue girl and labeled axes My rm qurm quot suu as n s I u a n We 451154 431555 w degrees m mm mum d u Ths ean make a lung m cnmplEX nmmand mare readable gnu Fur Exarnple1fynu dnn tlxke gm use unsee gnu Pnnrtn 4 0 me Enmmand wnuldhavebeen see nuguu vquot d m u 39nleneme39 gnuplut w vm quotMam n wulneemu use an expum pause 71 Enmmand see help pausetn makememnduwsuek mm m Wm r mm nntpmcesswe want only one cycle 2151nn7nzn AM Visualize your data with gnuplot 60f18 http www ibm com developerw orkslibrarylgnuplot Terminals a digression On startup you may have noticed that the terminal type is set to X1 1 Gnuplot has a modular design and can plot on several terminal devices This includes printing directly onto several kinds of printers including Epson HP and Imagen printers It can even plot on pseudodevices such as postscript and png Essentially this involves producing an output le instead of a viewable le or a printout This is the trick to including your graphs within other reports Although I have not noticed any difference on Windows and Linux the documentation recommends that you set the terminal type before setting the output le name Listing 4 setting output and terminal type set terminal png set output outputpng gnuplot recommends setting terminal before output The output filename to be set after setting terminal replot Now the le outputpng has the graph you just plotted and can be included in a larger report There are specialized terminals for many popular typesetting and drawing programs including Adobe Illustrator s et term ai fm Corel Draw s et term corel AutoCad s et term dxf and several LaTexrelated terminals eepic latex pst ric ks texdraw tpic and so on You can also get les in PostScript enhanced PostScript eps or the Adobe PDF formats Your version of gnuplot may not be compiled with all the terminal drivers for example Windows users do not need the X11 terminal and Linux users don t need the Windows terminal Similarly due to legal reasons gnuplot 40 removed support for gif terminals All terminals are not alike in their capabilities Some like LaTeX may not support rotation of text so if you set the ylabel as we did earlier it would appear differently on different terminals On the other hand you can use LaTeX commands in LaTeXspeci c terminals For example set yl abel quot sin theta quot notice we use two backslashes to produce the single backslash required by LaTeX gnuplot does the backslash processing on doublequoted strings before passing it to the terminal drivers Now you can include the output le in your LaTeX le using input output tex To achieve the same in PostScript terminals use the corresponding PostScript command Symbol q In both enhanced PostScript and LaTeX you can get superscripts using the notation x A s up er s crip t and xii s ulo s c rip t Notice also the abbreviated terminal and output commands Listing 5 Capabilities ofthe eps driver set term post enh enhanced Postscript essentially Postscript with bounding boxes set out 39gplteps set xlabel 39Symbol q 1 set ylabel 39sinA2Symbol ql plot sinx2 The code supplement in the Resources section has an example TeX le that showcases the above commands Mouse support New to version 40 the Windows and X11 terminals support mouse interaction Mouse support has two main uses coordinate tracking and zooming The current coordinates of the mouse pointer are shown on the lower left comer of the terminal window This can be copied to the clipboard by double clicking the rst mouse button This is useful when you need to set a label or an arrow which need explicit coordinates Use help arrow and help label to get more details on these commands You can also drag the second or rightclick mouse button to select a rectangular area to zoom in on In 3D plots you can drag the mouse to rotate the image pressing control changes only the view of the axes instead so for graphs that take too long to render you can change the axes rst and then release the control key to rerender the graph 8152007 1130 AM Visualize your data with gnuplot 7of18 http www ibm com developerw orkslibrarylgnuplot Mouse support also enables a bunch of useful hotkeys u unzooms the graph if you have zoomed in previously g toggles the grid 1 toggles logscale on both axes L toggles the logscale on the aXis nearest to the pointer r toggles a ruler which establishes an arbitrary point of origin When the ruler is enabled the bottom of the screen shows the X and y distances of the current mouse pointer from ruler origin as well as the Xy distances from the actual origin which is the same as the coordinates of the point In 3D the arrow keys can be used in lieu of the mouse drag to rotate the image The space bar raises the command window and q quits the terminal window To see all the options type h on a mouseenabled terminal Controlling scale and aspect ratio By default gnuplot uses a scaling factor of l for both the X and yaxes but it makes no effort to control the aspect ratio the ratio of the length of the yaXis to the length of the XaXis of the gure The terminal driver uses the default aspect ratio of the terminal Either the scaling factor or aspect ratio or both may be speci ed with the set s i z e command for example square is synonymous to an aspect ratio of 1 it scale yaxis by 2 retain xaxis size set size ratio square 12 The success of gnuplot in drawing a graph with a given aspect ratio may be limited by the capabilities of the terminal set si ze is also useful in conjunction with the multiplot command which is used to produce more than one graph on the same output screen or le Plotting more than one curve As the astute reader may have guessed from the comments above on replot gnuplot lets you graph multiple lines simultaneously Let us plot both the sine and the cosine curves The simple plot command would be plot si n x cos x the lines being graphed are separated by commas If you do not specify anything else gnuplot automatically displays the two graphs so that they are distinguishable from each other in terminals like Windows and X11 gnuplot uses different colors Monochrome terminals display the graphs using different kinds of lines By looking at the legend or key you should be able to tell which line in the graph is which Alternatively gnuplot lets you take greater control by specifying the style with which to draw a graph unset xtics it keep all other things simple plot sin x with iinespoints pointtype 5 Figure 5 Multiple curves cosx w boxes it 4 81520071130 AM Visual wur alumna guwlm t1pwww1h39n camMewapexwaxkshbnzyLglwlm My rm may smhng e we 132569 1 mm m duly plot Ha quotPM m plettlng Inhsexznple The H ml l cunslderenl s w quota ml e m r mess data ml a w an quotat F plot ts m H mm vquot amm 394 u use set style mettle llnespulntspnurversunsusethesyntax set funcmun style boxes Tunhzngethestyle usedfurplumng datasetsasuppusedtufunmunsuse set style data lmespsmtsset data style lmespsmtsmpnmvetemne samples in and hmle slnx Tu w uth as we as fur the 2 am 2151nn7nzn AM 9am szuahze Wm datawnh nglm up www mm curndewapexwaxkshbnzyquwlm cnsmecurve u lquot ml wd Linings Custmnizing are key m39 legmrl nthe graph Set my up lerr Set my bax Wat plwl SanO U e Smusam wlth hnESDmnts pamrtype s CDSOOI CDS1HE W lame lr 0 Figure 6 0mm key My am ml mhngle Angl m dawns azuzl 355524 Plotting related graphs on the same screen related gures as ne le man m mdude them separately Thebaslc u h m Lining 7 Mum39le example Set xrenee mm a Untament he fallawmq a hne up the axes a Set warqu r a annular rem meme serrmq the 5122 and mm befarE qmnq a a murmur m ae auxmm ll 3 AM szuahze wur dataw h nglm IUDfIX up www 1m curndewapexwaxkshbnzyquwlm e Tms Sets up baunmnq baxes and may be rE mred an me eemmeu 1 e Dane 1 reenvew ms takes mum mm mm mat made e and brmqs up a new Drmpt mnnmat gt mstead af mum Set mumpm e pm the rst qranh 5a me n takes a Quarter w the Screen Set me usus Set amqm uus um moo e pm the Setan graph 5a me u takes a Quarter w the Screen Set me usus e pm the mm qranh 5a me n takes a Quarter w the Screen usus e pm the mm graph 5a me u takes a Quarter w the Screen Set me usus Set amqm usu um JCDSEXJ e an me eermms nathmq ths matted unt ms meme 5 155L126 unset mnan e ramvE an tusmmuanan reset Figure 7 Multiplnt madness My m guvh My rm mph n a u e F u 4 a u 2 g u s u 2 u o u e a a Ana s w W dewvees m degrees My my warm My rm W i n mi so us 50 zelms m aeoms e w eauol 5 21 seems m 50015 w u Jnoms m ems m 5 an we We m Hegmns 2mm 41 am mdiqmr 2151nn7nzn AM Visualize your data with gnuplot ll of18 http www ibm com developerw orkslibrarylgnuplot Plotting data While most of this tutorial has for expository purposes concentrated on plotting the sinusoid you will most likely be plotting data from experiments or sales data or the like In this section we will demonstrate how to plot different graphs using IBM s stock price as the data set The raw data for this example is included in the Resources section Table 1 IBM stock price Date Open High Low Close 10Jun04 9023 9075 8989 9046 9Jun04 8990 9055 8981 9009 8Jun04 8864 9050 8840 9004 7Jun04 8875 8899 8801 8864 4Jun04 8795 8849 8750 8756 3Jun04 8785 8810 8735 8735 2Jun04 8864 8864 8789 8798 1Jun 04 8800 8848 8730 8812 Most data sets have numerical columns but this one represents a challenge because the xaxis is time data The following lines tell gnuplot how to read and format the time data on the xaxis see help time data and help set timefmt for more details Listing 8 Setting up timeseries data The x axis data is time The dates in the file look like 10 Jun 04 On the x axis we want tics like Jun 10 set xdata time set timefmt d b y set format x b d Once that is set up we can plot the opening price with the following command We choose to use straightline interpolation between the different opening prices and use the line spoint 5 style instead ofjust points plot quot31MayO4 quot quot11Jun04quot 39ibm dat39 using 1 2 with linespoints Figure 8 Charting IBM stock prices 8152007 1130 AM Visualize 3mm datawnh gnuplr nun www xbm snndeveluperwnrksuurnyLgnunlnq BM cpenmw Puczs v 575 szh Junm men mus Junm mus mus mm Janna JunDE Junm mu As always 317May704 114mm sets up he urange explmdy but is nn and x tsmcdy necessary Nntethatthe nun ma nfunerange needtn be speu edassmngsthat nnfm mtn the 1 true rne using xfnur urne fnrmat had 4 W Lu use uslng Gnuplnt is intelligent ennugn tn use me hme nt smug tn read me nLha39 Enlumns aspace m themddle fur Example 10 Jun 04 as nppnsedtn meJuneoawe vmuld need a d H F rm ulnmng style zmnV 39 whmhwewemfyas z3454 plat quot31May04 quot quotlJrJurrOQ clue 39dally prlces quot1 391bmdat39 uslng 1234s54 IEM39 wlth yerrnrbars Figure 9 Calculating averages 12 ma 81520071130AM szuahze wur datawnh nglm up www 1m camMewapexwmkshbnzyquwlm 51 dady mes BM Ha I I B7 MayZV mm JunUZ mm mm was JunUE mm was was mum mu values respemvely Weuse set harstu shuwlzrga tics furthe upmmg and clusmg values 59 bars 5 p10 quot31 May 4quotquot11Jurr 4quot 391hmdat39 usmg 12345 much Elnancehars Figure la Firming nance bars IKDfIX 2151nn7nznAM szuahze wur dataw h nglm Mule mp www 1m camMewapexwarkshbnzyquwlm bmdal swans m MnyEI mm Junm Jun i man mus mus mm mm mus mm mm pluttlng buxen39urbars and murplumng styles Dealing with reallife data sets OF Mr N V rmva VAN set aarams separator ltstr1nggt Similarly yuu can 215 marry acumments charms amar than 3mm ms r h he p datasetsthatcmbereadmthswaycanalsubehzndledusmg atherthe set data ms separator urby r W mquot a Fuwm v F r example plot vvlt awk quoti preprocessawk dataf119quot Unfununatelythsduesnutvmrk armssall slams MW pumt Furexample set aaaanls massmg 39NaN39 a The mag floatlng pulnt narrarnumhsr NutethaL pnurtu 4 n ma cummand was set massmg ltstr1nggt h 39flle39plut vmsv asmg 123ndplm vmsv asrag 91mm Buttubesafa alwayswemfytheculumnstuusevmhan a explicit culumns mm the result fths calculated Expressmns 2151nn7nzn AM Visualize your data with gnuplot 15 of18 http www ibm com developerw orkslibrarylgnuplot At other times you may end up with some data points that are not valid You can still plot such data sets if gnuplot can be told to ignore the invalid data points Gnuplot quietly ignores unde ned points so the trick is to use an unde ned yvalue like 10 when you come across an unsuitable point The Clike ternary operator comes very handy in expressing this See help t ernary if you are not familiar with this function it is also useful in defining piecewise functions Here is an example mentioned in help usi ng that lets you plot the second column as a yvalue unless the third column is more than 10 plot 39file39 using 1 3gtlO 2 lO An advanced example While this article has exposed you to most of the commands you will end up using commonly there may be occasions where you need to do more esoteric things In this section we brie y discuss some of these concepts and then include a script from one of the gnuplot demo les electrondem which plots an amplitudefrequency response plot of the sort commonly seen in electronics to illustrate their usage User de ned functions and variables You can de ne arbitrarily complex functions of your own such as Ajw below These can be parameterized pl p2 and you can de ne the parameter variables later on before using it in a pl ot command Complex numbers Gnuplot understands complex numbers The notation ab represents the complex number abi You can use the functions abs and arg to obtain the absolute value and the argument Dummy variables When you use sinx in a plot command gnuplot uses x as the dummy variable and gives it different values to obtain the samples When writing complex userde ned functions you can use traditional variable names used in the function de nitions and explicitly set the name of the dummy variable to use for example set dummy j w The x2 and y2 axes Apart from the familiar x and y axis along the bottom and the left edges of the graph you can also use the top of the graph x2 and the right end of the graph y2 as separate axes The axes are all independent of each other and you can set the range tics labels and scaling for example logscale separately Also the plot command can be made to use a different set of axes like x2y2 by using the axes clause By default the plot command plots against the x and yaxes This advanced feature is helpful when you need to simultaneously plot to lines whose ranges are of different orders of magnitude or have different units In the example below the yaxis plots the amplitude which has a maximum of 1 while the y2axis plots the phase which has a maximum value of 100 If plotted on the same set of axes the amplitude curve would be barely visible Logscale You can plot any of the axes in log scale with the set logscale command This plots the logarithm to base 10 ofthe values on the axis You can explicitly set the base to use for example set logscale 2 or set logscale xy 2 ifsetting it only for the major xy axes Equot W 5 U Here is an extract from the demo electrondem which ships with gnuplot This script uses all of the advanced concepts discussed above Listing 9 Amplitude frequency response AjW 0ljW0ljwpl ll0ljWp2 pl 10 p2 10000 set dummy jw set grid x y2 set key default set logscale xy set title quotAmplitude and Phase Frequency Response 81520071130 AM szuahze wur datawnh nglm up www 1m camMewapexwmkshbnzyquwlm SEI mm M mums SEI xra qE 11 5mm 9 5 mu llmnme w Ame hase w Amwj memes SEI anmsme yz pm mam Janp1tarq AEJWJJ axes xzyz Figure 11 Amplitude and phase frequency respnnse Ampmude m pm FvKuenzy Raspnnse 7 7 mm shswm 7 vmv WM an m w W 3 z 5quot 2 f 7 2 39 E 392quot g 4n an an H mm mm mm mm mm Mums Conclu In Lhs 2mm Althuugh we parametrlc and pulzr cuurdmates help polar m curver mng whth ts ausarde ned curvetu agven damsel Omler mn s an and awhule zmcle cmle easuybe devutedtu m butluuk up help at and the begnnerxgnde andnp subrtupmstu get 25L Tips forfrequem usage As h w Yunnan sax3211 sets 39nmLhecun39Entsessmnusmg save set 39fllename39 save var 119mm save func r n passedtuasmgleplutcummzndfursxzmpleJhexrrzngemplDt 19 p1 slnxThese lescanberead mung 2151nn7nznAM Visualize your data with gnuplot l7of18 http www ibm com developerw orkslibrarylgnuplot back using load ltfilegt Gnuplot also looks up a le called gnuplot on startup It looks rst in the current directory and then in the home directory of the user The USERPROFILE directory in Windows If the initialization le is found gnuplot executes the commands in it Some users use this for setting the terminal type and de ning frequentlyused functions or variables Down load Name Size Download method sourcezip ZKB HTTP Information about download methods Resources Visit the official site for gnuplot and download the latest version D0 please note that gnuplot is not GPL d nor in any way related to GNU or the Free Software Foundation older GNU bulletin explains quotCuriously gnuplot was neither written nor named for the GNU Project the name is a coincidence Various GNU programs use gnuplotquot Indeed gnuplot works exceptionally well in combination with the GNU plotutils see also the plotutils documentation The of cial Gnuplot FAQ is very useful as is the unofficial not so Freguently Asked Questions site the latter has speci c information about using gnuplot in scienti c papers A Google search on quotgnuplot introductionquot or quotgnuplot tutorial yields several short gnuplot 37x tutorials that can be useful even though they reference the previous and not the most recent release version Download the IBM stock price data 1ibmdat1 used for the data plots and the example TeX le 1inputtex which shows how you can include gnuplot plots in a LaTeX report The article quot Data visualization using PerlT quot developerWorks 2003 discusses plotting with Perl For an overview of using ImageMagick from the command line read quotGraphics from the command linequot developerWorks July 2003 quot ntroduction to Scalable Vector Graphics developerWorks 2004 shows how to to easily generate graphics such as graphs and charts from database information and how to to add animation and interactivity to graphics Find more resources for Linux developers in the developerWorks Linux zone Browse for books on these and other technical topics Develop and test your Linux applications using the latest IBM tools and middleware with a developerWorks Subscription you get IBM software from WebSphere DB2 Lotus Rational and Tivoli and a license to use the software for 12 months all for less money than you might think Download nocharge trial versions of selected developerWorks Subscription products that run on Linux 8152007 1130 AM Visualize your data with gnuplot http www ibm com developerw orkslibrarylgnuplot including WebSphere Studio Site Developer WebSphere SDK for Web services WebSphere Application Server DB2 Universal Database Personal Developers Edition Tivoli Access Manager and Lotus Domino Server from the Speedstart your LinuX app section of developerWorks For an even speedier start help yourself to a productbyproduct collection of howto articles and tech support About the author Nishanth R Sastry received his bachelor s degree in Computer Science and Engineering in 1999 graduating with distinction from the RV College of Engineering Bangalore University India In 2001 he obtained a master s degree in Computer Science from the University of Texas at Austin He is an alunmus of IBM s Extreme Blue internship program and is now a Staff Software Engineer working on IBM Lotus Workplace You can reach him at nishanth sastryusibmcom 18 of18 8152007 1130 AM