Difference between revisions of "Example Jobs"

From Statistics Cluster
Jump to navigation Jump to search
(Created page with "== C example == === The Problem and the Code === === Preparation for Job Submission === === Job Submission and Management === == R example == === The Problem and the Code =...")
 
Line 2: Line 2:
 
=== The Problem and the Code ===
 
=== The Problem and the Code ===
  
 +
<nowiki>#include <stdio.h></nowiki><br>
 +
<nowiki>#include <stdlib.h></nowiki><br>
 +
<nowiki>#include <time.h></nowiki><br>
  
 +
int main(int argc, char *argv[])<br>
 +
<nowiki>{</nowiki><br>
 +
<nowiki>int i,N,incirc=0;</nowiki><br>
 +
<nowiki>double x,y,circrad2;</nowiki><br>
 +
 +
<nowiki>sscanf(argv[1], "%d", &N); // get iteration number from input</nowiki><br>
 +
<nowiki>srand(time(NULL));        // seed random number generator</nowiki><br>
 +
 +
<nowiki>circrad2=1.0*RAND_MAX; </nowiki><br>
 +
<nowiki>circrad2*=circrad2;        // Define radius squared </nowiki><br>
 +
 +
<nowiki>for(i=0;i<N;i++){</nowiki><br>
 +
<nowiki>x=1.0*rand(); y=1.0*rand();    // get rand. point and</nowiki><br>
 +
<nowiki>incirc += (x*x+y*y) < circrad2; // check if inside circle</nowiki><br>
 +
} <br>
 +
 +
<nowiki>printf("pi=%.12f\n",4.0*incirc/N); // display probability</nowiki><br>
 +
return 0;<br>
 +
}
 
=== Preparation for Job Submission ===
 
=== Preparation for Job Submission ===
  
 
=== Job Submission and Management ===
 
=== Job Submission and Management ===
 +
 
== R example ==
 
== R example ==
 
=== The Problem and the Code ===
 
=== The Problem and the Code ===

Revision as of 19:59, 19 July 2013

C example

The Problem and the Code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{
int i,N,incirc=0;
double x,y,circrad2;

sscanf(argv[1], "%d", &N); // get iteration number from input
srand(time(NULL)); // seed random number generator

circrad2=1.0*RAND_MAX;
circrad2*=circrad2; // Define radius squared

for(i=0;i<N;i++){
x=1.0*rand(); y=1.0*rand(); // get rand. point and
incirc += (x*x+y*y) < circrad2; // check if inside circle
}

printf("pi=%.12f\n",4.0*incirc/N); // display probability
return 0;
}

Preparation for Job Submission

Job Submission and Management

R example

The Problem and the Code

Preparation for Job Submission

Job Submission and Management

Acknowledgement

Examples provided by Igor Senderovich