Serial job example
This example runs a single process on one CPU to sum a set of
1,000,000 exponentials. It consists of four parts:
- A script for the LSF batch subsystem that submits the job
to lightning
- Fortran code that runs the example
- C code that runs the same example
- C++ code that runs the same example
To run this example, you have two choices:
In the /usr/local/examples/lsf/batch/ directory on lightning:
cp serial.* $PWD
Submit the example codes to the LSF batch subsystem by entering:
bsub < serial.lsf
Copy the codes on this page and paste them into your own
files:
- Copy the
LSF batch job script below and paste it into
a file named serial.lsf in your working directory on
lightning.
- Copy the
Fortran code below and paste it into a file named
serial.f in your working directory on lightning.
- Copy the
C code below and paste it into a file named
serial.c in your working directory on lightning.
- Copy the
C++ code below and paste it into a file named
serial.cc in your working directory on lightning.
- Submit the example codes to the LSF batch subsystem by
entering:
bsub < serial.lsf
Studying this example will help you prepare your own serial jobs
for submittal to lightning via LSF.
#!/bin/ksh
#
# LSF batch script to run the serial code examples
#
#BSUB -n 1 # number of tasks
#BSUB -o seriallsf.out # output filename
#BSUB -e seriallsf.err # input filename
#BSUB -J seriallsf.test # job name
#BSUB -q regular # queue
# Fortran example
pgf90 -Mextend -o serial_f -Mextend serial.f
./serial_f
rm serial_f
# C example
pgcc -o serial_c serial.c
./serial_c
rm serial_c
# C++ example
pgCC --no_auto_instantiation -o serial_cc serial.cc
./serial_cc
rm serial_cc
program main
implicit none
integer i
integer hz, clock0, clock1, t
real(kind=8):: sum, elapsed
sum=0.0
call system_clock(count_rate = hz)
call system_clock(count = clock0)
do i=1,1000000
sum=sum+exp(.00000001*i)
end do
call system_clock(count = clock1)
elapsed = real(clock1 - clock0) / hz
print 10, sum, elapsed
10 format(' f90 Serial Results: Sum = ',1pe12.6,' Loop time = ',0pf12.8)
stop
end
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
main()
{
int i;
double sum, elapsed, rtc();
elapsed=rtc();
for(i=1; i<1000000; i++)
{
sum += exp( .00000001 * (double)i );
}
elapsed=rtc()-elapsed;
printf( " c Serial Results: Sum = %11e Loop time = %8f \n",sum,elapsed );
exit (0);
}
double rtc()
{
struct timeval time;
gettimeofday(&time,NULL);
return ( (double)(time.tv_sec*1000000+time.tv_usec)/1000000 );
}
#include <iostream>
#include <string>
#include <math.h>
#include <sys/time.h>
using namespace std;
//------ Class Defs-----------------------------------------------------
class exp_sum {
public:
double elapsed;
double sum();
private:
double summer;
struct timeval time;
double rtc();
};
double exp_sum::sum()
{
int i;
summer=0.0;
elapsed=rtc();
for(i=1; i<1000000; i++)
{
summer += exp( .00000001 * (double)i );
}
elapsed=rtc()-elapsed;
return summer;
};
double exp_sum:: rtc()
{
gettimeofday(&time,NULL);
return ( (double)(time.tv_sec*1000000+time.tv_usec)/1000000 );
};
//-----------------------------------------------------------------------
//----------MAIN Program--------------------------------------------------
int main()
{
exp_sum total;
double value;
value=total.sum();
cout << " CC Serial Results: Sum = " << value << " Loop time = " << total.elapsed << endl;
};
Next page |
IBM Linux cluster systems fundamentals -
Table of contents
If you have questions about this document, please contact
SCD Customer Support.
You can also reach us by telephone 24 hours a day, seven days a week at
303-497-1278.
Additional contact methods:
consult1@ucar.edu
and during
business hours
in NCAR Mesa Lab Suite 39.
© Copyright 2005. University Corporation for Atmospheric
Research (UCAR). All Rights Reserved.
Address of this page:
http://www.scd.ucar.edu/docs/lightning/examples/serial.jsp
|