~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/batch_job.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#ifndef BATCH_JOB_H
 
9
#define BATCH_JOB_H
 
10
 
 
11
#include <time.h>
 
12
 
 
13
/** @file batch_job.h Batch job submission.
 
14
This module implements batch job submission to multiple systems,
 
15
including Condor, SGE, Work Queue, Xgrid, and local Unix processes.
 
16
This simplifies the construction
 
17
of parallel abstractions that need a simple form of parallel process execution.
 
18
*/
 
19
 
 
20
/** An integer type indicating a unique batch job number.*/
 
21
typedef int batch_job_id_t;
 
22
 
 
23
/** Indicates which type of batch submission to use. */
 
24
typedef enum {
 
25
        BATCH_QUEUE_TYPE_UNKNOWN=-1, /**< An invalid batch queue type. */
 
26
        BATCH_QUEUE_TYPE_LOCAL,      /**< Batch jobs will run as local processes. */
 
27
        BATCH_QUEUE_TYPE_CONDOR,     /**< Batch jobs will be sent to Condor pool. */
 
28
        BATCH_QUEUE_TYPE_SGE,        /**< Batch jobs will be sent to Sun Grid Engine. */
 
29
        BATCH_QUEUE_TYPE_WORK_QUEUE,  /**< Batch jobs will be sent to the Work Queue. */
 
30
        BATCH_QUEUE_TYPE_XGRID,       /**< Batch jobs will be sent to the Xgrid. */
 
31
        BATCH_QUEUE_TYPE_HADOOP       /**< Batch jobs will be sent to Hadoop. */
 
32
} batch_queue_type_t;
 
33
 
 
34
/** Describes a batch job when it has completed. */
 
35
struct batch_job_info {
 
36
        time_t submitted;       /**< Time the job was submitted to the system. */
 
37
        time_t started;         /**< Time the job actually began executing. */
 
38
        time_t finished;        /**< Time at which the job actually completed. */
 
39
        int exited_normally;    /**< Non-zero if the job ran to completion, zero otherwise. */
 
40
        int exit_code;          /**< The result code of the job, if it exited normally. */
 
41
        int exit_signal;        /**< The signal by which the job was killed, if it exited abnormally. */
 
42
};
 
43
 
 
44
/** Create a new batch queue.
 
45
@param type The type of the queue.
 
46
@return A new batch queue object on success, null on failure.
 
47
*/
 
48
struct batch_queue * batch_queue_create( batch_queue_type_t type );
 
49
 
 
50
/** Submit a simple batch job.
 
51
@param q The queue to submit to.
 
52
@param cmdline The command line to execute.  This line will be interpreted by the shell, so it may include output redirection, multiple commands, pipes, and so forth.
 
53
@param input_files A comma separated list of all input files that will be required by the job.  Null pointer is equivalent to empty string.  This must also include the executable and any dependent programs.
 
54
@param output_files A comma separated list of all output files to retrieve from the job.  Null pointer is equivalent to empty string.
 
55
@return On success, returns a unique identifier for the batch job.  On failure, returns a negative number.
 
56
*/
 
57
 
 
58
batch_job_id_t batch_job_submit_simple(
 
59
        struct batch_queue *q,
 
60
        const char *cmdline,
 
61
        const char *input_files,
 
62
        const char *output_files );
 
63
 
 
64
/** Submit a batch job.
 
65
@param q The queue to submit to.
 
66
@param cmd The command to execute.
 
67
@param args The command line arguments.
 
68
@param infile The standard input file.
 
69
@param outfile The standard output file.
 
70
@param errfile The standard error file.
 
71
@param extra_input_files A comma separated list of extra input files that will be required by the job.  Null pointer is equivalent to empty string.
 
72
@param extra_output_files A comma separated list of extra output files to retrieve from the job.  Null pointer is equivalent to empty string.
 
73
@return On success, returns a unique positive jobid.  Zero or a negative number indicates a failure to submit this job.
 
74
*/
 
75
 
 
76
batch_job_id_t batch_job_submit(
 
77
        struct batch_queue *q,
 
78
        const char *cmd,
 
79
        const char *args,
 
80
        const char *infile,
 
81
        const char *outfile,
 
82
        const char *errfile,
 
83
        const char *extra_input_files,
 
84
        const char *extra_output_files );
 
85
 
 
86
/** Wait for any batch job to complete.
 
87
Blocks until a batch job completes.
 
88
@param q The queue to wait on.
 
89
@param info Pointer to a @ref batch_job_info structure that will be filled in with the details of the completed job.
 
90
@return If greater than zero, indicates the jobid of the completed job.
 
91
If equal to zero, there were no more jobs to wait for.
 
92
If less than zero, the operation was interrupted by a system event, but may be tried again.
 
93
*/
 
94
 
 
95
batch_job_id_t batch_job_wait( struct batch_queue *q, struct batch_job_info *info );
 
96
 
 
97
/** Wait for any batch job to complete, with a timeout.
 
98
Blocks until a batch job completes or the current time exceeds stoptime.
 
99
@param q The queue to wait on.
 
100
@param info Pointer to a @ref batch_job_info structure that will be filled in with the details of the completed job.
 
101
@param stoptime An absolute time at which to stop waiting.  If less than or equal to the current time,
 
102
then this function will check for a complete job but will not block.
 
103
@return If greater than zero, indicates the jobid of the completed job.
 
104
If equal to zero, there were no more jobs to wait for.
 
105
If less than zero, the operation timed out or was interrupted by a system event, but may be tried again.
 
106
*/
 
107
 
 
108
batch_job_id_t batch_job_wait_timeout( struct batch_queue *q, struct batch_job_info *info, time_t stoptime );
 
109
 
 
110
/** Remove a batch job.
 
111
This call will start the removal process.
 
112
You must still call @ref batch_job_wait to wait for the removal to complete.
 
113
@param q The queue to remove from.
 
114
@param jobid The job to be removed.
 
115
@return Greater than zero if the job exists and was removed, zero otherwise.
 
116
*/
 
117
 
 
118
int batch_job_remove( struct batch_queue *q, batch_job_id_t jobid );
 
119
 
 
120
/** Converts a string into a batch queue type.
 
121
@param str A string indicating the work queue type, which may be "unix", "condor", "sge", "wq", or "xgrid".
 
122
@return The batch queue type corresponding to the string, or BATCH_QUEUE_TYPE_UNKNOWN if the string is invalid.
 
123
*/
 
124
batch_queue_type_t batch_queue_type_from_string( const char *str );
 
125
 
 
126
/** Converts a batch queue type to a string.
 
127
@param t A @ref batch_queue_type_t.
 
128
@return A string corresponding to the batch queue type.
 
129
*/
 
130
const char * batch_queue_type_to_string( batch_queue_type_t t );
 
131
 
 
132
/** Set the log file used by the batch queue.
 
133
This is an optional call that will only affect batch queue types
 
134
that use an internal logfile; currently only Condor.
 
135
@param q The batch queue to adjust.
 
136
@param logfile Name of the logfile to use.
 
137
*/
 
138
void batch_queue_set_logfile( struct batch_queue *q, const char *logfile );
 
139
 
 
140
/** Add extra options to pass to the underlying batch system.
 
141
This call specifies additional options to be passed to the batch system each
 
142
time a job is submitted.  It may be called once to apply to all subsequent
 
143
jobs, or it may be called before each submission.  If the queue type
 
144
is @ref BATCH_QUEUE_TYPE_CONDOR, the options must be valid submit file
 
145
properties like <tt>requirements = (Memory>100)</tt>.
 
146
If the batch queue type is @ref BATCH_QUEUE_TYPE_SGE, the extra text will be added as options to
 
147
the <tt>qsub</tt> command.  This call has no effect on other queue types.
 
148
@param q The batch queue to adjust.
 
149
@param options The options to pass to the batch system.
 
150
*/
 
151
void batch_queue_set_options( struct batch_queue *q, const char *options );
 
152
 
 
153
/** Delete a batch queue.
 
154
Note that this function just destroys the internal data structures,
 
155
it does not abort running jobs.  To properly clean up running jobs,
 
156
you must call @ref batch_job_wait until it returns zero, or
 
157
call @ref batch_job_remove on all runnings jobs.
 
158
@param q The queue to delete.
 
159
*/
 
160
void batch_queue_delete( struct batch_queue *q );
 
161
 
 
162
/** Returns the list of queue types supported by this module.
 
163
Useful for including in help-option outputs.
 
164
@return A static string listing the types of queues supported.
 
165
*/
 
166
 
 
167
const char * batch_queue_type_string();
 
168
 
 
169
/** Returns the port number of the batch queue.
 
170
Currently only relevant for the work queue implementation.
 
171
@param q The batch queue of interest.
 
172
@return The port number in use, or zero if not applicable.
 
173
*/
 
174
int batch_queue_port( struct batch_queue *q );
 
175
 
 
176
#endif