/*___INFO__MARK_BEGIN__*/ /************************************************************************* * * The Contents of this file are made available subject to the terms of * the Sun Industry Standards Source License Version 1.2 * * Sun Microsystems Inc., March, 2001 * * * Sun Industry Standards Source License Version 1.2 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.2 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2001 by Sun Microsystems, Inc. * * All Rights Reserved. * ************************************************************************/ /*___INFO__MARK_END__*/ #include #include #include #include #include #include #include #include #include #include "drmaa.h" /* program defaults */ int njobs = 100; int nthreads = 1; int dowait = 1; int quiet = 0; char *native_spec = "-w n"; char *job_path = NULL; char **job_args = NULL; char *scenario = NULL; char *site_b = NULL; drmaa_job_template_t *jt; static drmaa_job_template_t *create_job_template(const char *job_path, const char *project, int i); static void *submit_jobs(void *arg); static void get_gmt(struct timeval *); static int submit_by_project(const char *project); static void usage(void) { fprintf(stderr, "usage: test_drmaa_perf [ options ] []\n"); fprintf(stderr, " -jobs number of jobs per thread (default 100)\n"); fprintf(stderr, " -native native specification passed (default \"-w n\")\n"); fprintf(stderr, " -threads number of submission thread (default 1)\n"); fprintf(stderr, " -wait [yes|no] wait for job completion (default yes)\n"); fprintf(stderr, " -quiet [yes|no] wait for job completion (default no)\n"); fprintf(stderr, " -scenario [queue|type|number|pe].[none|resource|hostgroup|softresource|softhostgroup] options -jobs/-threads be ignored\n"); /* scenario assumes - queue "all.q" - projects "project[1-4]" - consumables "APP1 ... APP40" - queue attribute type=all be used with all.q */ return; } #define DELTA_SECONDS(t1, t2) (((double)t2.tv_sec - (double)t1.tv_sec) + ((double)t2.tv_usec - (double)t1.tv_usec)/1000000) int main(int argc, char *argv[]) { char diagnosis[DRMAA_ERROR_STRING_BUFFER]; char *s, jobid[100]; int drmaa_errno, i; int ret = 0; struct timeval start_s, finish_s, wait_s; if (argc<2) { usage(); return 1; } i = 1; do { if (!strcmp("-help", argv[i]) || !strcmp("-h", argv[i])) { usage(); return 0; } else if (!strcmp("-jobs", argv[i])) { i++; if (argc < i+1) { usage(); return 1; } njobs = atoi(argv[i]); i++; } else if (!strcmp("-native", argv[i])) { i++; if (argc < i+1) { usage(); return 1; } native_spec = argv[i]; i++; } else if (!strcmp("-threads", argv[i])) { if (argc < i+1) { usage(); return 1; } i++; nthreads = atoi(argv[i]); i++; } else if (!strcmp("-quiet", argv[i])) { i++; if (argc < i+1) { usage(); return 1; } if (!strcmp("yes", argv[i]) || !strcmp("y", argv[i])) quiet = 1; else if (!strcmp("no", argv[i]) || !strcmp("n", argv[i])) quiet = 0; else { usage(); return 1; } i++; } else if (!strcmp("-wait", argv[i])) { i++; if (argc < i+1) { usage(); return 1; } if (!strcmp("yes", argv[i]) || !strcmp("y", argv[i])) dowait = 1; else if (!strcmp("no", argv[i]) || !strcmp("n", argv[i])) dowait = 0; else { usage(); return 1; } i++; } else if (!strcmp("-scenario", argv[i])) { i++; if (argc < i+1) { usage(); return 1; } s = strchr(argv[i], '.'); *s = '\0'; if (strcmp("queue", argv[i]) && strcmp("type", argv[i]) && strcmp("number", argv[i]) && strcmp("pe", argv[i])) { usage(); return 1; } scenario = strdup(argv[i]); s++; if (strcmp("hostgroup", s) && strcmp("resource", s) && strcmp("none", s) && strcmp("softresource", s) && strcmp("softhostgroup", s)) { usage(); return 1; } site_b = strdup(s); i++; } else { job_path = argv[i]; i++; if (job_path[0]=='-') { usage(); return 1; } if (argv[i]) { job_args = &argv[i]; } } } while (i < argc && !job_path); if (!job_path) { usage(); return 1; } #if 0 printf("job_path: \"%s\"\n", job_path); printf("njobs: %d\n", njobs); printf("nthreads: %d\n", nthreads); printf("native: %s\n", native_spec); printf("dowait: %s\n", dowait?"yes":"no"); printf("quiet: %s\n", quiet?"yes":"no"); printf("scenario: %s\n", scenario?scenario:""); printf("site_b: %s\n", site_b?site_b:""); printf("1st arg: %s\n", job_args?job_args[0]:""); #endif if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) { fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis); return 1; } get_gmt(&start_s); if (!scenario) { if (!(jt = create_job_template(job_path, NULL, 0))) { fprintf(stderr, "create_sleeper_job_template() failed\n"); return 1; } if (nthreads==1) { if (submit_jobs(&argv[i])) return 1; } else { pthread_t *ids = NULL; ids = (pthread_t *)malloc(sizeof (pthread_t) * nthreads); for (i = 0; i < nthreads; i++) { if (pthread_create(&ids[i], NULL, submit_jobs, NULL)) { fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno)); return 1; } } for (i = 0; i < nthreads; i++) { pthread_join(ids[i], NULL); } } drmaa_delete_job_template(jt, NULL, 0); } else { if (submit_by_project("project1") || submit_by_project("project2") || submit_by_project("project3") || submit_by_project("project4")) return 1; } get_gmt(&finish_s); printf("submission took %8.3f seconds\n", DELTA_SECONDS(start_s, finish_s)); if (dowait) { int success = 1; for (i=0; i