Skip to content

Commit

Permalink
Merge pull request #3 from adammoody/lsf
Browse files Browse the repository at this point in the history
Add LSF support.
  • Loading branch information
morrone authored Oct 28, 2017
2 parents 2c66245 + f6f38e2 commit b59b30f
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 1 deletion.
111 changes: 111 additions & 0 deletions config/x_ac_lsf.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
##*****************************************************************************
## $Id: x_ac_lsf.m4 8192 2006-05-25 00:15:05Z morrone $
##*****************************************************************************
# AUTHOR:
# Adam Moody <[email protected]>
# (Originally Chris Dunlap <[email protected]>)
#
# SYNOPSIS:
# X_AC_LSF()
#
# DESCRIPTION:
# Check the usual suspects for a LSF installation,
# updating CPPFLAGS and LDFLAGS as necessary.
#
# WARNINGS:
# This macro must be placed after AC_PROG_CC and before AC_PROG_LIBTOOL.
##*****************************************************************************

AC_DEFUN([X_AC_LSF], [
# LSF installs have an include at the top level,
# but they bury the libs under a subdirectory as in:
# <path>/
# include/
# lsbatch.h
# linux3.10-glibc2.17-ppc64le/
# lib/
# libbat.so
#
# If certain LSF environment variables are set, they
# could be used to locate include and lib dirs.
#
# To get path to the include file:
# grep LSF_INCLUDEDIR $LSF_ENVDIR/lsf.conf
#
# The path to the library directory:
# echo $LSF_LIBDIR
# TODO: hard coded subdirectory for LSF
lsflib_subdir="linux3.10-glibc2.17-ppc64le"
# various libs needed to call lsb_ functions
LSF_LIBADD="-lbat -llsf -lrt -lnsl"
_x_ac_lsf_dirs="/usr"
_x_ac_lsf_libs="lib64 lib"
AC_ARG_WITH(
[lsf],
AS_HELP_STRING(--with-lsf=PATH,Specify path to lsf installation),
[_x_ac_lsf_dirs="$withval"
with_lsf=yes],
[with_lsf=no])
_backup_libs="$LIBS"
if test "$with_lsf" = no; then
# Check for LSF library in the default location.
AC_CHECK_LIB([bat], [lsb_init], [], [], [$LSF_LIBADD])
fi
LIBS="$_backup_libs"
if test "$ac_cv_lib_bat_lsb_init" != yes; then
AC_CACHE_CHECK(
[for LSF installation],
[x_ac_cv_lsf_dir],
[
for d in $_x_ac_lsf_dirs; do
test -d "$d" || continue
test -d "$d/include" || continue
test -d "$d/include/lsf" || continue
test -f "$d/include/lsf/lsbatch.h" || continue
for bit in $_x_ac_lsf_libs; do
test -d "$d/$lsflib_subdir/$bit" || continue
_x_ac_lsf_libs_save="$LIBS"
LIBS="-L$d/$lsflib_subdir/$bit $LSF_LIBADD $LIBS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([lsb_init(NULL);])],
[AS_VAR_SET([x_ac_cv_lsf_dir], [$d])
AS_VAR_SET([x_ac_cv_lsf_libdir], [$d/$lsflib_subdir/$bit])]
)
LIBS="$_x_ac_lsf_libs_save"
test -n "$x_ac_cv_lsf_dir" && break
done
test -n "$x_ac_cv_lsf_dir" && break
done
])
fi
if test "$with_lsf" = no \
&& test "$ac_cv_lib_bat_lsb_open" = yes; then
LSF_CPPFLAGS=""
LSF_LDFLAGS=""
elif test -n "$x_ac_cv_lsf_dir"; then
LSF_CPPFLAGS="-I$x_ac_cv_lsf_dir/include"
LSF_LDFLAGS="-L$x_ac_cv_lsf_libdir"
else
if test "$with_lsf" = yes; then
AC_MSG_ERROR([LSF is not in specified location!])
else
AC_MSG_WARN([unable to locate LSF installation])
fi
fi
AC_SUBST(LSF_LIBADD)
AC_SUBST(LSF_CPPFLAGS)
AC_SUBST(LSF_LDFLAGS)
AM_CONDITIONAL(WITH_LSF,
test -n "$x_ac_cv_lsf_dir" || test "$ac_cv_lib_bat_lsb_init" = yes)
])
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AC_DEFINE([LIBYOGRT_LT_AGE], [], [libyogrt library version "age"])
X_AC_SLURM
X_AC_LCRM
X_AC_MOAB
X_AC_LSF

aix_64bit_mode=no
using_aix=no
Expand Down Expand Up @@ -69,6 +70,7 @@ AC_CONFIG_FILES([libyogrt.spec
src/slurm/Makefile
src/lcrm/Makefile
src/moab/Makefile
src/lsf/Makefile
src/aixslurm/Makefile])

AC_OUTPUT
5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ endif
if WITH_MOAB
MOAB_DIR = moab
endif
if WITH_LSF
LSF_DIR = lsf
endif

SUBDIRS = none $(SLURM_DIR) $(LCRM_DIR) $(MOAB_DIR) $(AIXSLURM_DIR)
SUBDIRS = none $(SLURM_DIR) $(LCRM_DIR) $(MOAB_DIR) $(AIXSLURM_DIR) $(LSF_DIR)

lib_LTLIBRARIES = libyogrt.la
libyogrt_la_SOURCES = yogrt.c
Expand Down
11 changes: 11 additions & 0 deletions src/lsf/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
AM_CPPFLAGS = -I$(top_srcdir)/src

sublibdir = $(libdir)/libyogrt
sublib_LTLIBRARIES = libyogrt-lsf.la
libyogrt_lsf_la_SOURCES = internal.c
libyogrt_lsf_la_LIBADD = $(LSF_LIBADD)
libyogrt_lsf_la_CPPFLAGS = $(AM_CPPFLAGS) $(LSF_CPPFLAGS)
libyogrt_lsf_la_LDFLAGS = $(LSF_LDFLAGS) \
-no-undefined \
-export-symbols-regex "^internal_.*" \
-version-info $(LIBYOGRT_LT_CURRENT):$(LIBYOGRT_LT_REVISION):$(LIBYOGRT_LT_AGE)
144 changes: 144 additions & 0 deletions src/lsf/internal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/***************************************************************************
* Copyright (C) 2017, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Adam Moody <[email protected]>.
* UCRL-CODE-235649. All rights reserved.
*
* This file is part of libyogrt.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
***************************************************************************/

#include <stdlib.h>
#include <lsf/lsbatch.h>

#include "internal_yogrt.h"

/* This uses LSF's LSBLIB function to get the time remaining in a job.
* At the time of writing, documentation for this API was available here:
*
* https://www.ibm.com/support/knowledgecenter/SSWRJV_10.1.0/api_reference/index.html
*
* http://publibfp.dhe.ibm.com/epubs/pdf/c2753121.pdf */

int verbosity = 0;
int jobid_valid = 0;
LS_LONG_INT jobid;

int internal_init(int verb)
{
verbosity = verb;

/* initialize the lsb library */
int rc = lsb_init(NULL);
if (rc != 0) {
lsb_perror("Error calling lsb_init()");
}

/* look up our jobid from $LSB_JOBID and store it */
char* value = getenv("LSB_JOBID");
if (value) {
/* TODO: is there an lsb_ function to convert this string? */
debug2("LSF: $LSB_JOBID=%s.\n", value);
jobid = (LS_LONG_INT) strtol(value, NULL, 10);
jobid_valid = 1;
} else {
/* ERROR: failed to get job id */
error("LSF: Failed to get jobid. $LSB_JOBID is not set!\n");
return 0;
}

/* Don't know how to determine if job is running under Moab.
Just assume always valid. */
return 1;
}

char *internal_backend_name(void)
{
return "LSF";
}

int internal_get_rem_time(time_t now, time_t last_update, int cached)
{
int secs_left = 0;

/* only do this lookup with a valid jobid */
if (! jobid_valid) {
error("LSF: No valid jobid to lookup!\n");
return -1;
}

/* open connection for job records */
int jobs = lsb_openjobinfo(jobid, NULL, NULL, NULL, NULL, CUR_JOB);
if (jobs == -1) {
error("LSF: Error calling lsb_openjobinfo() for jobid=%s.\n", lsb_jobid2str(jobid));
lsb_perror("Error opening jobs");
return -1;
}

debug2("LSF: lsb_openjobinfo() job count=%d.\n", jobs);
if (jobs == 1) {
/* get job info for this job */
struct jobInfoEnt* job = lsb_readjobinfo(&jobs);
if (job == NULL) {
error("LSF: Failed to read job info for jobid=%s: lsb_readjobinfo() failed.\n", lsb_jobid2str(jobid));
lsb_perror("Failed to read job info");
secs_left = -1;
} else {
/* get run limit of the job */
int run_limit = job->submit.rLimits[LSF_RLIMIT_RUN];
debug2("LSF: RunLimit=%d.\n", run_limit);
if (run_limit < 0) {
/* there is no run limit imposed on the job,
* so return the max time */
secs_left = INT_MAX;
} else {
/* got a valid run limit,
* get current run time for the job */
int run_time = job->runTime;

/* compute time remaining */
secs_left = run_limit - run_time;
if (secs_left < 0) {
secs_left = 0;
}

debug2("LSF: RunLimit=%d RunTime=%d Rem=%d.\n", run_limit, run_time, secs_left);
}
}
} else if (jobs > 1) {
error("LSF: lsb_readjobinfo() returned more than one job for jobid=%s.\n", lsb_jobid2str(jobid));
secs_left = -1;
} else {
error("LSF: Failed to find info for jobid=%s.\n", lsb_jobid2str(jobid));
secs_left = -1;
}

/* close the connection */
lsb_closejobinfo();

debug2("LSF reports remaining time of %d sec.\n", secs_left);
return secs_left;
}

int internal_get_rank(void)
{
return 0;
}

int internal_fudge(void)
{
return 0;
}

0 comments on commit b59b30f

Please sign in to comment.