[ Platform Documentation ] [ Title ] [ Contents ] [ Previous ] [ Next ] [ Index ]
This chapter gives examples of how to:
- Use LSF to submit jobs
- Submit jobs using
lsb_submit()
with error checking- Submit jobs using
lsb_submit()
without error checking- How to use the
bsub
command.
- Submitting a Simple Batch Job
- Submitting a Batch Job with Error Checking
- Submitting a Batch Job Using lsb_submit() to Emulate the bsub Command
- Submitting a Batch Job to a Specific Queue
- Supplementary files
[ Top ]
Submitting a Simple Batch Job
/****************************************************** * LSBLIB -- Examples * * lsb_submit() * Submit command as an lsbatch job using the simplest * version of lsb_submit() * Note: there is no error checking in this program. ******************************************************/
#include <lsf/lsbatch.h> #include "combine_arg.h"/* Use the header file
lsbatch.h
when writing programs that use the LSF API. */
/* To use the function "combine_arg
" to combine arguments on the command line include its header file "combine_arg.h
". */int main(int argc, char **argv) { int i;
struct submit req; memset(&req, 0, sizeof(req)); struct submitReply reply;/* req holds the job specification. */
/* initializes req to avoid core dump */
/* reply holds the result of submission. */
lsb_init(argv[0]);/* Before using any batch library function, call
lsb_init(). lsb_init()
initializes the configuration environment. */
lsb_submit(&req, &reply);/*Call
lsb_submit()
to submit the job with specifications. */exit(0); } /* main */[ Top ]
Submitting a Batch Job with Error Checking
/****************************************************** * LSBLIB -- Examples * * lsb_submit() * Use lsb_submit() in the simplest way with error * checking *****************************************************/
#include <stdlib.h> #include <stdio.h> #include <lsf/lsbatch.h> #include "combine_arg.h" /* To use the function "combine_arg
" to combine arguments on the command line include its header file "combine_arg.h
". */ int main(int argc, char **argv) { int i; struct submit req; /* job specifications */ memset(&req, 0, sizeof(req)); /* initializes req */ struct submitReply reply; /* results of job submission */ int jobId; /* job ID of submitted job*/
if (lsb_init(argv[0]) < 0) { lsb_perror("simbsub: lsb_init() failed"); exit(-1); }/* Check the return value of
lsb_init()
to ensure that the initialization of LSBLIB is successful. */
if (argc < 2) { fprintf(stderr, "Usage: simbsub command\n"); exit(-1); }/* Check if the input is in the correct format: "
./simbsub COMMAND
[ARGUMENTS]
"
(simbsub
is the name of this executable program). */
req.options = 0; /* Set options and options2 to 0 */ req.options2 = 0; /* to indicate no options are selected */ req.beginTime = 0; /* Set beginTime to 0 to dispatch job without delay */ req.termTime = 0; /* Set termTime to 0 to indicate no terminating deadline */ /* Set Resource limits to default*/ for (i = 0; i < LSF_RLIM_NLIMITS; i++) req.rLimits[i] = DEFAULT_RLIMIT; /*Initialize the initial number and maximum number of processors needed by a (parallel) job*/ req.numProcessors = 1; req.maxNumProcessors = 1; req.command = combine_arg(argc,argv); /* Initialize command line of job */ printf("----------------------------------------------\n"); jobId = lsb_submit(&req, &reply); /*submit the job with specifications */ exit(0); } /* main */[ Top ]
Submitting a Batch Job Using lsb_submit() to Emulate the bsub Command
/****************************************************** * LSBLIB -- Examples * * lsb_submit() usage that is equivalent to "bsub" command * with no options ******************************************************/
#include <stdlib.h> #include <stdio.h> #include <lsf/lsbatch.h> #include "combine_arg.h" /* To use the function "combine_arg
" to combine arguments on the command line include its header file "combine_arg.h
". */ int main(int argc, char **argv) { int i; struct submit req; /* job specifications */ memset(&req, 0, sizeof(req)); /* initializes req */ struct submitReply reply; /* results of job submission */ int jobId; /* job ID of submitted job */ /* initialize LSBLIB and get the configuration environment */ if (lsb_init(argv[0]) < 0) { lsb_perror("simbsub: lsb_init() failed"); exit(-1); } /* check if input is in the right format: "./simbsub COMMAND ARGUMENTS" */ if (argc < 2) { fprintf(stderr, "Usage: simbsub command\n"); exit(-1); }
for (i = 0; i < LSF_RLIM_NLIMITS; i++) req.rLimits[i] = DEFAULT_RLIMIT; req.numProcessors = 1; req.maxNumProcessors = 1;/ * In order to synchronize the job specification in
lsb_submit()
to the default used bybsub
, the following variables are defined. (By default,bsub
runs the job in 1 processor with no resource limit.) */
/*Resource limits are initialized to default limits (no limit).*/
/* Initialize the initial number and maximum number of processors needed by a (parallel) job. */req.options = 0; /* Set options and options2 to 0 */ req.options2 = 0; /* Select no options is selected */ req.beginTime = 0; /* Dispatch job without delay */ req.termTime = 0; /* Use no terminating deadline */ req.command = combine_arg(argc,argv); /* job command line */ printf("-----------------------------------------------\n"); jobId = lsb_submit(&req, &reply); /* submit the job with specifications */ if (jobId < 0) /* if job submission fails, lsb_submit returns -1 */ switch (lsberrno) { /* and sets lsberrno to indicate the error */ case LSBE_QUEUE_USE: case LSBE_QUEUE_CLOSED: lsb_perror(reply.queue); exit(-1); default: lsb_perror(NULL); exit(-1); } exit(0); } /* main */[ Top ]
Submitting a Batch Job to a Specific Queue
/****************************************************** * LSBLIB -- Examples * * bsub -q * This program is equivalent to using the "bsub -q queue_name" * command ******************************************************/
#include <stdio.h> #include <stdlib.h> #include <lsf/lsbatch.h> #include "combine_arg.h" /* To use the function "combine_arg
" to combine arguments on the command line include its header file "combine_arg.h
". */ int main(int argc, char **argv) { int i; struct submit req; /* job specifications */ memset(&req, 0, sizeof(req)); /* initializes req */ struct submitReply reply; /* results of job submission */ int jobId; /* job ID of submitted job */ /* Initialize LSBLIB and get the configuration environment */ if (lsb_init(argv[0]) < 0) { lsb_perror("simbsub: lsb_init() failed"); exit(-1); } /*Check if input is in the right format: "./simbsub COMMAND ARGUMENTS" */ if (argc < 2) { fprintf(stderr, "Usage: simbsub command\n"); exit(-1); }
req.options |= SUB_QUEUE; req.queue = "normal";/*
SUB_QUEUE
indicates that the job is dispatched to a specific queue. */
/* Queue name is given by user (e.g. "normal")
The queue name has to be valid (check the queue usingbqueues
) */req.options2 = 0; for (i = 0; i < LSF_RLIM_NLIMITS; i++) /* resources limits */ req.rLimits[i] = DEFAULT_RLIMIT; req.beginTime = 0; /* specific dispatch date and time */ req.termTime = 0; /* specifies job termination deadline */ req.numProcessors = 1; /* initial num of processors needed by a (parallel) job */ req.maxNumProcessors = 1; /*max num of processors required to run the parallel job */ req.command = combine_arg(argc,argv); /* command line of job */ jobId = lsb_submit(&req, &reply); /* submit the job with specifications */ if (jobId < 0) /* if job submission fails, lsb_submit returns -1 */ switch (lsberrno) { /* and sets lsberrno to indicate the error */ case LSBE_QUEUE_USE: case LSBE_QUEUE_CLOSED: lsb_perror(reply.queue); exit(-1); default: lsb_perror(NULL); exit(-1);} exit(0); } /* main */[ Top ]
Supplementary files
/* combine_arg.h */ #include <stdlib.h> #include <string.h> /* combine_arg.h */ char *combine_arg(int c,char **arg); /* combine the arguments on command line */ /* combine_arg.c */ /* combine the arguments on command line */ #include "combine_arg.h" char *combine_arg(int c,char **arg) { int i,j=0; char *s; /* counts the number of characters in the arguments */ for (i=1;i<c;i++) j+=strlen(arg[i])+1; /* paste the arguments */ s = (char *)malloc(j*sizeof(char)); memset (s, "\0", sizeof(s)); strcat(s,arg[1]); for (i=2;i<c;i++) { strcat(s," "); strcat(s,arg[i]); } return s; } /* submit_cmd.h */ #include <lsf/lsbatch.h> #include "combine_arg.h" int submit_cmd(struct submit *req, struct submitReply *reply, int c, char **arg); /* submit_cmd.c */ /* submit a job with specifications (without error checking) */ #include "submit_cmd.h" int submit_cmd(struct submit *req, struct submitReply *reply, int c, char **arg) { int i; lsb_init(arg[0]); for (i = 0; i < LSF_RLIM_NLIMITS; i++) req->rLimits[i] = DEFAULT_RLIMIT; req->numProcessors = 1; req->maxNumProcessors = 1; req->options = 0; req->options2 = 0; req->command = combine_arg(c,arg); req->beginTime = 0; req->termTime = 0; return lsb_submit(req, reply); }[ Top ]
[ Platform Documentation ] [ Title ] [ Contents ] [ Previous ] [ Next ] [ Index ]
Date Modified: March 13, 2009
Platform Computing: www.platform.com
Platform Support: support@platform.com
Platform Information Development: doc@platform.com
Copyright © 1994-2009 Platform Computing Corporation. All rights reserved.