~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/common/env.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  src/common/env.c - add an environment variable to environment vector
3
3
 *****************************************************************************
4
4
 *  Copyright (C) 2002-2007 The Regents of the University of California.
5
 
 *  Copyright (C) 2008 Lawrence Livermore National Security.
 
5
 *  Copyright (C) 2008-2009 Lawrence Livermore National Security.
6
6
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7
7
 *  Written by Mark Grondona <mgrondona@llnl.gov>, Danny Auble <da@llnl.gov>.
8
 
 *  LLNL-CODE-402394.
 
8
 *  CODE-OCEC-09-009. All rights reserved.
9
9
 *  
10
10
 *  This file is part of SLURM, a resource management program.
11
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 
11
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
12
 *  Please also read the included file: DISCLAIMER.
12
13
 *  
13
14
 *  SLURM is free software; you can redistribute it and/or modify it under
14
15
 *  the terms of the GNU General Public License as published by the Free
146
147
        return false;
147
148
}
148
149
 
 
150
static void _set_distribution(task_dist_states_t distribution,
 
151
                              char **dist, char **lllp_dist)
 
152
{
 
153
        if (((int)distribution >= 0)
 
154
            &&  (distribution != SLURM_DIST_UNKNOWN)) {
 
155
                switch(distribution) {
 
156
                case SLURM_DIST_CYCLIC:
 
157
                        *dist      = "cyclic";
 
158
                        break;
 
159
                case SLURM_DIST_BLOCK:
 
160
                        *dist      = "block";
 
161
                        break;
 
162
                case SLURM_DIST_PLANE:
 
163
                        *dist      = "plane";
 
164
                        *lllp_dist = "plane";
 
165
                        break;
 
166
                case SLURM_DIST_ARBITRARY:
 
167
                        *dist      = "arbitrary";
 
168
                        break;
 
169
                case SLURM_DIST_CYCLIC_CYCLIC:
 
170
                        *dist      = "cyclic";
 
171
                        *lllp_dist = "cyclic";
 
172
                        break;
 
173
                case SLURM_DIST_CYCLIC_BLOCK:
 
174
                        *dist      = "cyclic";
 
175
                        *lllp_dist = "block";
 
176
                        break;
 
177
                case SLURM_DIST_BLOCK_CYCLIC:
 
178
                        *dist      = "block";
 
179
                        *lllp_dist = "cyclic";
 
180
                        break;
 
181
                case SLURM_DIST_BLOCK_BLOCK:
 
182
                        *dist      = "block";
 
183
                        *lllp_dist = "block";
 
184
                        break;
 
185
                default:
 
186
                        error("unknown dist, type %d", distribution);
 
187
                        break;
 
188
                }
 
189
        }
 
190
}
 
191
 
149
192
/*
150
193
 * Return the number of elements in the environment `env'
151
194
 */
262
305
        return NULL;
263
306
}
264
307
 
265
 
int setup_env(env_t *env)
 
308
int setup_env(env_t *env, bool preserve_env)
266
309
{
267
310
        int rc = SLURM_SUCCESS;
268
 
        char *dist = NULL;
269
 
        char *lllp_dist = NULL;
 
311
        char *dist = NULL, *lllp_dist = NULL;
270
312
        char addrbuf[INET_ADDRSTRLEN];
271
313
 
272
314
        if (env == NULL)
278
320
                 rc = SLURM_FAILURE;
279
321
        }
280
322
 
281
 
        if (env->nprocs
 
323
        if (!preserve_env && env->nprocs
282
324
           && setenvf(&env->env, "SLURM_NPROCS", "%d", env->nprocs)) {
283
325
                error("Unable to set SLURM_NPROCS environment variable");
284
326
                rc = SLURM_FAILURE;
319
361
                rc = SLURM_FAILURE;
320
362
        } 
321
363
 
322
 
        if (((int)env->distribution >= 0)
323
 
        &&  (env->distribution != SLURM_DIST_UNKNOWN)) {
324
 
                switch(env->distribution) {
325
 
                case SLURM_DIST_CYCLIC:
326
 
                        dist      = "cyclic";
327
 
                        lllp_dist = "";
328
 
                        break;
329
 
                case SLURM_DIST_BLOCK:
330
 
                        dist      = "block";
331
 
                        lllp_dist = "";
332
 
                        break;
333
 
                case SLURM_DIST_PLANE:
334
 
                        dist      = "plane";
335
 
                        lllp_dist = "plane";
336
 
                        break;
337
 
                case SLURM_DIST_ARBITRARY:
338
 
                        dist      = "arbitrary";
339
 
                        lllp_dist = "";
340
 
                        break;
341
 
                case SLURM_DIST_CYCLIC_CYCLIC:
342
 
                        dist      = "cyclic";
343
 
                        lllp_dist = "cyclic";
344
 
                        break;
345
 
                case SLURM_DIST_CYCLIC_BLOCK:
346
 
                        dist      = "cyclic";
347
 
                        lllp_dist = "block";
348
 
                        break;
349
 
                case SLURM_DIST_BLOCK_CYCLIC:
350
 
                        dist      = "block";
351
 
                        lllp_dist = "cyclic";
352
 
                        break;
353
 
                case SLURM_DIST_BLOCK_BLOCK:
354
 
                        dist      = "block";
355
 
                        lllp_dist = "block";
356
 
                        break;
357
 
                default:
358
 
                        error("unknown dist, type %d", env->distribution);
359
 
                        dist      = "unknown";
360
 
                        lllp_dist = "unknown";
361
 
                        break;
362
 
                }
363
 
 
 
364
        _set_distribution(env->distribution, &dist, &lllp_dist);
 
365
        if(dist) 
364
366
                if (setenvf(&env->env, "SLURM_DISTRIBUTION", "%s", dist)) {
365
367
                        error("Can't set SLURM_DISTRIBUTION env variable");
366
368
                        rc = SLURM_FAILURE;
367
369
                }
368
370
 
369
 
                if (setenvf(&env->env, "SLURM_DIST_PLANESIZE", "%d", 
 
371
        if(env->distribution == SLURM_DIST_PLANE) 
 
372
                if (setenvf(&env->env, "SLURM_DIST_PLANESIZE", "%u", 
370
373
                            env->plane_size)) {
371
 
                        error("Can't set SLURM_DIST_PLANESIZE env variable");
 
374
                        error("Can't set SLURM_DIST_PLANESIZE "
 
375
                              "env variable");
372
376
                        rc = SLURM_FAILURE;
373
377
                }
374
 
 
 
378
        
 
379
        if(lllp_dist)
375
380
                if (setenvf(&env->env, "SLURM_DIST_LLLP", "%s", lllp_dist)) {
376
381
                        error("Can't set SLURM_DIST_LLLP env variable");
377
382
                        rc = SLURM_FAILURE;
378
383
                }
379
 
        }
 
384
        
380
385
        
381
386
        if (env->cpu_bind_type) {
382
387
                char *str_verbose, *str_bind_type, *str_bind_list;
383
388
                char *str_bind;
384
389
                int len;
385
390
 
386
 
                unsetenvp(env->env, "SLURM_CPU_BIND_VERBOSE");
387
 
                unsetenvp(env->env, "SLURM_CPU_BIND_TYPE");
388
 
                unsetenvp(env->env, "SLURM_CPU_BIND_LIST");
389
 
                unsetenvp(env->env, "SLURM_CPU_BIND");
 
391
                if (env->batch_flag) {
 
392
                        unsetenvp(env->env, "SBATCH_CPU_BIND_VERBOSE");
 
393
                        unsetenvp(env->env, "SBATCH_CPU_BIND_TYPE");
 
394
                        unsetenvp(env->env, "SBATCH_CPU_BIND_LIST");
 
395
                        unsetenvp(env->env, "SBATCH_CPU_BIND");
 
396
                } else {
 
397
                        unsetenvp(env->env, "SLURM_CPU_BIND_VERBOSE");
 
398
                        unsetenvp(env->env, "SLURM_CPU_BIND_TYPE");
 
399
                        unsetenvp(env->env, "SLURM_CPU_BIND_LIST");
 
400
                        unsetenvp(env->env, "SLURM_CPU_BIND");
 
401
                }
390
402
 
391
403
                str_verbose = xstrdup ("");
392
404
                if (env->cpu_bind_type & CPU_BIND_VERBOSE) {
394
406
                } else {
395
407
                        xstrcat(str_verbose, "quiet");
396
408
                }
397
 
                if (setenvf(&env->env, "SLURM_CPU_BIND_VERBOSE", str_verbose)) {
398
 
                        error("Unable to set SLURM_CPU_BIND_VERBOSE");
399
 
                        rc = SLURM_FAILURE;
400
 
                }
401
 
 
402
409
                str_bind_type = xstrdup ("");
403
410
                if (env->cpu_bind_type & CPU_BIND_TO_THREADS) {
404
411
                        xstrcat(str_bind_type, "threads,");
406
413
                        xstrcat(str_bind_type, "cores,");
407
414
                } else if (env->cpu_bind_type & CPU_BIND_TO_SOCKETS) {
408
415
                        xstrcat(str_bind_type, "sockets,");
 
416
                } else if (env->cpu_bind_type & CPU_BIND_TO_LDOMS) {
 
417
                        xstrcat(str_bind_type, "ldoms,");
409
418
                }
410
419
                if (env->cpu_bind_type & CPU_BIND_NONE) {
411
420
                        xstrcat(str_bind_type, "none");
415
424
                        xstrcat(str_bind_type, "map_cpu:");
416
425
                } else if (env->cpu_bind_type & CPU_BIND_MASK) {
417
426
                        xstrcat(str_bind_type, "mask_cpu:");
 
427
                } else if (env->cpu_bind_type & CPU_BIND_LDRANK) {
 
428
                        xstrcat(str_bind_type, "rank_ldom");
 
429
                } else if (env->cpu_bind_type & CPU_BIND_LDMAP) {
 
430
                        xstrcat(str_bind_type, "map_ldom:");
 
431
                } else if (env->cpu_bind_type & CPU_BIND_LDMASK) {
 
432
                        xstrcat(str_bind_type, "mask_ldom:");
418
433
                }
419
434
                len = strlen(str_bind_type);
420
435
                if (len) {              /* remove a possible trailing ',' */
422
437
                                str_bind_type[len-1] = '\0';
423
438
                        }
424
439
                }
425
 
                if (setenvf(&env->env, "SLURM_CPU_BIND_TYPE", str_bind_type)) {
426
 
                        error("Unable to set SLURM_CPU_BIND_TYPE");
427
 
                        rc = SLURM_FAILURE;
428
 
                }
429
 
 
430
440
                str_bind_list = xstrdup ("");
431
441
                if (env->cpu_bind) {
432
442
                        xstrcat(str_bind_list, env->cpu_bind);
433
443
                }
434
 
                if (setenvf(&env->env, "SLURM_CPU_BIND_LIST", str_bind_list)) {
435
 
                        error("Unable to set SLURM_CPU_BIND_LIST");
436
 
                        rc = SLURM_FAILURE;
437
 
                }
438
 
 
439
444
                str_bind = xstrdup ("");
440
445
                xstrcat(str_bind, str_verbose);
441
 
                if (str_bind[0]) {              /* add ',' if str_verbose */
 
446
                if (str_bind[0] && str_bind_type && str_bind_type[0])
442
447
                        xstrcatchar(str_bind, ',');
443
 
                }
444
448
                xstrcat(str_bind, str_bind_type);
445
449
                xstrcat(str_bind, str_bind_list);
446
450
 
447
 
                if (setenvf(&env->env, "SLURM_CPU_BIND", str_bind)) {
448
 
                        error("Unable to set SLURM_CPU_BIND");
449
 
                        rc = SLURM_FAILURE;
 
451
                if (env->batch_flag) {
 
452
                        if (setenvf(&env->env, "SBATCH_CPU_BIND_VERBOSE",
 
453
                                    str_verbose)) {
 
454
                                error("Unable to set SBATCH_CPU_BIND_VERBOSE");
 
455
                                rc = SLURM_FAILURE;
 
456
                        }
 
457
                        if (setenvf(&env->env, "SBATCH_CPU_BIND_TYPE",
 
458
                                    str_bind_type)) {
 
459
                                error("Unable to set SBATCH_CPU_BIND_TYPE");
 
460
                                rc = SLURM_FAILURE;
 
461
                        }
 
462
                        if (setenvf(&env->env, "SBATCH_CPU_BIND_LIST",
 
463
                                    str_bind_list)) {
 
464
                                error("Unable to set SBATCH_CPU_BIND_LIST");
 
465
                                rc = SLURM_FAILURE;
 
466
                        }
 
467
                        if (setenvf(&env->env, "SBATCH_CPU_BIND", str_bind)) {
 
468
                                error("Unable to set SBATCH_CPU_BIND");
 
469
                                rc = SLURM_FAILURE;
 
470
                        }
 
471
                } else {
 
472
                        if (setenvf(&env->env, "SLURM_CPU_BIND_VERBOSE",
 
473
                                    str_verbose)) {
 
474
                                error("Unable to set SLURM_CPU_BIND_VERBOSE");
 
475
                                rc = SLURM_FAILURE;
 
476
                        }
 
477
                        if (setenvf(&env->env, "SLURM_CPU_BIND_TYPE",
 
478
                                    str_bind_type)) {
 
479
                                error("Unable to set SLURM_CPU_BIND_TYPE");
 
480
                                rc = SLURM_FAILURE;
 
481
                        }
 
482
                        if (setenvf(&env->env, "SLURM_CPU_BIND_LIST",
 
483
                                    str_bind_list)) {
 
484
                                error("Unable to set SLURM_CPU_BIND_LIST");
 
485
                                rc = SLURM_FAILURE;
 
486
                        }
 
487
                        if (setenvf(&env->env, "SLURM_CPU_BIND", str_bind)) {
 
488
                                error("Unable to set SLURM_CPU_BIND");
 
489
                                rc = SLURM_FAILURE;
 
490
                        }
450
491
                }
451
492
        }
452
493
 
454
495
                char *str_verbose, *str_bind_type, *str_bind_list;
455
496
                char *str_bind;
456
497
 
457
 
                unsetenvp(env->env, "SLURM_MEM_BIND_VERBOSE");
458
 
                unsetenvp(env->env, "SLURM_MEM_BIND_TYPE");
459
 
                unsetenvp(env->env, "SLURM_MEM_BIND_LIST");
460
 
                unsetenvp(env->env, "SLURM_MEM_BIND");
 
498
                if (env->batch_flag) {
 
499
                        unsetenvp(env->env, "SBATCH_MEM_BIND_VERBOSE");
 
500
                        unsetenvp(env->env, "SBATCH_MEM_BIND_TYPE");
 
501
                        unsetenvp(env->env, "SBATCH_MEM_BIND_LIST");
 
502
                        unsetenvp(env->env, "SBATCH_MEM_BIND");
 
503
                } else {
 
504
                        unsetenvp(env->env, "SLURM_MEM_BIND_VERBOSE");
 
505
                        unsetenvp(env->env, "SLURM_MEM_BIND_TYPE");
 
506
                        unsetenvp(env->env, "SLURM_MEM_BIND_LIST");
 
507
                        unsetenvp(env->env, "SLURM_MEM_BIND");
 
508
                }
461
509
 
462
510
                str_verbose = xstrdup ("");
463
511
                if (env->mem_bind_type & MEM_BIND_VERBOSE) {
465
513
                } else {
466
514
                        xstrcat(str_verbose, "quiet");
467
515
                }
468
 
                if (setenvf(&env->env, "SLURM_MEM_BIND_VERBOSE", str_verbose)) {
469
 
                        error("Unable to set SLURM_MEM_BIND_VERBOSE");
470
 
                        rc = SLURM_FAILURE;
471
 
                }
472
 
 
473
516
                str_bind_type = xstrdup ("");
474
517
                if (env->mem_bind_type & MEM_BIND_NONE) {
475
518
                        xstrcat(str_bind_type, "none");
482
525
                } else if (env->mem_bind_type & MEM_BIND_LOCAL) {
483
526
                        xstrcat(str_bind_type, "local");
484
527
                }
485
 
                if (setenvf(&env->env, "SLURM_MEM_BIND_TYPE", str_bind_type)) {
486
 
                        error("Unable to set SLURM_MEM_BIND_TYPE");
487
 
                        rc = SLURM_FAILURE;
488
 
                }
489
 
 
490
528
                str_bind_list = xstrdup ("");
491
529
                if (env->mem_bind) {
492
530
                        xstrcat(str_bind_list, env->mem_bind);
493
531
                }
494
 
                if (setenvf(&env->env, "SLURM_MEM_BIND_LIST", str_bind_list)) {
495
 
                        error("Unable to set SLURM_MEM_BIND_LIST");
496
 
                        rc = SLURM_FAILURE;
497
 
                }
498
 
 
499
532
                str_bind = xstrdup ("");
500
533
                xstrcat(str_bind, str_verbose);
501
534
                if (str_bind[0]) {              /* add ',' if str_verbose */
504
537
                xstrcat(str_bind, str_bind_type);
505
538
                xstrcat(str_bind, str_bind_list);
506
539
 
507
 
                if (setenvf(&env->env, "SLURM_MEM_BIND", str_bind)) {
508
 
                        error("Unable to set SLURM_MEM_BIND");
509
 
                        rc = SLURM_FAILURE;
 
540
                if (env->batch_flag) {
 
541
                        if (setenvf(&env->env, "SBATCH_MEM_BIND_VERBOSE",
 
542
                                    str_verbose)) {
 
543
                                error("Unable to set SBATCH_MEM_BIND_VERBOSE");
 
544
                                rc = SLURM_FAILURE;
 
545
                        }
 
546
                        if (setenvf(&env->env, "SBATCH_MEM_BIND_TYPE",
 
547
                                    str_bind_type)) {
 
548
                                error("Unable to set SBATCH_MEM_BIND_TYPE");
 
549
                                rc = SLURM_FAILURE;
 
550
                        }
 
551
                        if (setenvf(&env->env, "SBATCH_MEM_BIND_LIST",
 
552
                                    str_bind_list)) {
 
553
                                error("Unable to set SBATCH_MEM_BIND_LIST");
 
554
                                rc = SLURM_FAILURE;
 
555
                        }
 
556
                        if (setenvf(&env->env, "SBATCH_MEM_BIND", str_bind)) {
 
557
                                error("Unable to set SBATCH_MEM_BIND");
 
558
                                rc = SLURM_FAILURE;
 
559
                        }
 
560
                } else {
 
561
                        if (setenvf(&env->env, "SLURM_MEM_BIND_VERBOSE",
 
562
                                    str_verbose)) {
 
563
                                error("Unable to set SLURM_MEM_BIND_VERBOSE");
 
564
                                rc = SLURM_FAILURE;
 
565
                        }
 
566
                        if (setenvf(&env->env, "SLURM_MEM_BIND_TYPE",
 
567
                                    str_bind_type)) {
 
568
                                error("Unable to set SLURM_MEM_BIND_TYPE");
 
569
                                rc = SLURM_FAILURE;
 
570
                        }
 
571
                        if (setenvf(&env->env, "SLURM_MEM_BIND_LIST",
 
572
                                    str_bind_list)) {
 
573
                                error("Unable to set SLURM_MEM_BIND_LIST");
 
574
                                rc = SLURM_FAILURE;
 
575
                        }
 
576
                        if (setenvf(&env->env, "SLURM_MEM_BIND", str_bind)) {
 
577
                                error("Unable to set SLURM_MEM_BIND");
 
578
                                rc = SLURM_FAILURE;
 
579
                        }
510
580
                }
511
581
        }
512
582
 
528
598
                rc = SLURM_FAILURE;
529
599
        }
530
600
 
531
 
#ifdef HAVE_BG
532
601
        if(env->select_jobinfo) {
 
602
#ifdef HAVE_BG
533
603
                char *bgl_part_id = NULL;
534
604
                select_g_get_jobinfo(env->select_jobinfo, 
535
605
                                     SELECT_DATA_BLOCK_ID, &bgl_part_id);
560
630
                        error("Can't set MPIRUN_PARTITION "
561
631
                              "environment variable");
562
632
                
 
633
#endif
 
634
 
 
635
#ifdef HAVE_CRAY_XT
 
636
                char *resv_id = NULL;
 
637
                select_g_get_jobinfo(env->select_jobinfo, 
 
638
                                     SELECT_DATA_RESV_ID, &resv_id);
 
639
                if (resv_id) {
 
640
                        if(setenvf(&env->env, 
 
641
                                   "BASIL_RESVERATION_ID", "%s", resv_id))
 
642
                                rc = SLURM_FAILURE;
 
643
                } else 
 
644
                        rc = SLURM_FAILURE;
 
645
                
 
646
                if(rc == SLURM_FAILURE)
 
647
                        error("Can't set BASIL_RESVERATION_ID "
 
648
                              "environment variable");
 
649
                xfree(resv_id);
 
650
#endif
563
651
        }
564
 
#endif
565
652
 
566
 
        if (env->jobid >= 0
567
 
            && setenvf(&env->env, "SLURM_JOBID", "%d", env->jobid)) {
568
 
                error("Unable to set SLURM_JOBID environment");
569
 
                rc = SLURM_FAILURE;
 
653
        if (env->jobid >= 0) {
 
654
                if (setenvf(&env->env, "SLURM_JOB_ID", "%d", env->jobid)) {
 
655
                        error("Unable to set SLURM_JOB_ID environment");
 
656
                        rc = SLURM_FAILURE;
 
657
                }
 
658
                /* and for backwards compatability... */
 
659
                if (setenvf(&env->env, "SLURM_JOBID", "%d", env->jobid)) {
 
660
                        error("Unable to set SLURM_JOBID environment");
 
661
                        rc = SLURM_FAILURE;
 
662
                }
570
663
        }
571
664
        
572
665
        if (env->nodeid >= 0
593
686
                rc = SLURM_FAILURE;
594
687
        }
595
688
        
596
 
        if (env->nhosts
 
689
        if (!preserve_env && env->nhosts
597
690
            && setenvf(&env->env, "SLURM_NNODES", "%d", env->nhosts)) {
598
691
                error("Unable to set SLURM_NNODES environment var");
599
692
                rc = SLURM_FAILURE;
605
698
                rc = SLURM_FAILURE;
606
699
        }
607
700
        
608
 
        if (env->task_count 
 
701
        if (!preserve_env && env->task_count 
609
702
            && setenvf (&env->env, 
610
703
                        "SLURM_TASKS_PER_NODE", "%s", env->task_count)) {
611
704
                error ("Can't set SLURM_TASKS_PER_NODE env variable");
618
711
                error ("Can't set SLURM_SRUN_COMM_PORT env variable");
619
712
                rc = SLURM_FAILURE;
620
713
        }
621
 
        if (env->comm_hostname
622
 
            && setenvf (&env->env, "SLURM_SRUN_COMM_HOST", "%s", 
623
 
                        env->comm_hostname)) {
624
 
                error ("Can't set SLURM_SRUN_COMM_HOST env variable");
625
 
                rc = SLURM_FAILURE;
626
 
        }
627
 
                
 
714
 
628
715
        if (env->cli) {
629
716
                
630
717
                slurm_print_slurm_addr (env->cli, addrbuf, INET_ADDRSTRLEN);
683
770
                error("Can't set SLURM_PTY_WIN_ROW env variable");
684
771
                rc = SLURM_FAILURE;
685
772
        }
686
 
        if (env->ckpt_path 
687
 
        && setenvf(&env->env, "SLURM_CHECKPOINT_PATH", "%s", env->ckpt_path)) {
688
 
                error("Can't set SLURM_CHECKPOINT_PATH env variable");
689
 
                rc = SLURM_FAILURE;
690
 
        }
 
773
        if (env->ckpt_dir 
 
774
        && setenvf(&env->env, "SLURM_CHECKPOINT_IMAGE_DIR", "%s", 
 
775
                   env->ckpt_dir)) {
 
776
                error("Can't set SLURM_CHECKPOINT_IMAGE_DIR env variable");
 
777
                rc = SLURM_FAILURE;
 
778
        }
 
779
 
 
780
        if (env->restart_cnt &&
 
781
            setenvf(&env->env, "SLURM_RESTART_COUNT", "%u", env->restart_cnt)) {
 
782
                error("Can't set SLURM_RESTART_COUNT env variable");
 
783
                rc = SLURM_FAILURE;
 
784
        }
 
785
 
691
786
        return rc;
692
787
}
693
788
 
743
838
/*
744
839
 * The cpus-per-node representation in SLURM (and perhaps tasks-per-node
745
840
 * in the future) is stored in a compressed format comprised of two
746
 
 * equal-length arrays of uint32_t, and an integer holding the array length.
747
 
 * In one array an element represents a count (number of cpus, number of tasks,
 
841
 * equal-length arrays, and an integer holding the array length.  In one
 
842
 * array an element represents a count (number of cpus, number of tasks,
748
843
 * etc.), and the corresponding element in the other array contains the
749
844
 * number of times the count is repeated sequentially in the uncompressed
750
845
 * something-per-node array.
753
848
 * array.  Free with xfree().
754
849
 */
755
850
extern char *uint32_compressed_to_str(uint32_t array_len,
756
 
                                      const uint32_t *array,
 
851
                                      const uint16_t *array,
757
852
                                      const uint32_t *array_reps)
758
853
{
759
854
        int i;
787
882
 *      SLURM_JOB_NODELIST
788
883
 *      SLURM_JOB_CPUS_PER_NODE
789
884
 *      LOADLBATCH (AIX only)
790
 
 *      MPIRUN_PARTITION, MPIRUN_NOFREE, and MPIRUN_NOALLOCATE (BGL only)
 
885
 *      SLURM_BG_NUM_NODES, MPIRUN_PARTITION, MPIRUN_NOFREE, and
 
886
 *      MPIRUN_NOALLOCATE (BGL only)
791
887
 *
792
888
 * Sets OBSOLETE variables (needed for MPI, do not remove):
793
889
 *      SLURM_JOBID
795
891
 *      SLURM_NODELIST
796
892
 *      SLURM_TASKS_PER_NODE 
797
893
 */
798
 
void
 
894
int
799
895
env_array_for_job(char ***dest, const resource_allocation_response_msg_t *alloc,
800
896
                  const job_desc_msg_t *desc)
801
897
{
 
898
#ifdef HAVE_CRAY_XT
 
899
        char *resv_id = NULL;
 
900
#endif
802
901
        char *tmp = NULL;
 
902
        char *dist = NULL, *lllp_dist = NULL;
803
903
        slurm_step_layout_t *step_layout = NULL;
804
904
        uint32_t num_tasks = desc->num_tasks;
 
905
        int rc = SLURM_SUCCESS;
 
906
 
 
907
#ifdef HAVE_BG
 
908
        uint32_t node_cnt = alloc->node_cnt;
 
909
        select_g_get_jobinfo(alloc->select_jobinfo, 
 
910
                             SELECT_DATA_NODE_CNT,
 
911
                             &node_cnt);
 
912
        env_array_overwrite_fmt(dest, "SLURM_BG_NUM_NODES", "%u", node_cnt);
 
913
#endif
805
914
 
806
915
        env_array_overwrite_fmt(dest, "SLURM_JOB_ID", "%u", alloc->job_id);
807
916
        env_array_overwrite_fmt(dest, "SLURM_JOB_NUM_NODES", "%u",
809
918
        env_array_overwrite_fmt(dest, "SLURM_JOB_NODELIST", "%s",
810
919
                                alloc->node_list);
811
920
 
812
 
        tmp = uint32_compressed_to_str((uint32_t)alloc->num_cpu_groups,
 
921
        _set_distribution(desc->task_dist, &dist, &lllp_dist);
 
922
        if(dist) 
 
923
                env_array_overwrite_fmt(dest, "SLURM_DISTRIBUTION", "%s",
 
924
                                        dist);
 
925
        
 
926
        if(desc->task_dist == SLURM_DIST_PLANE) 
 
927
                env_array_overwrite_fmt(dest, "SLURM_DIST_PLANESIZE",
 
928
                                        "%u", desc->plane_size);
 
929
        
 
930
        if(lllp_dist)
 
931
                env_array_overwrite_fmt(dest, "SLURM_DIST_LLLP", "%s", 
 
932
                                        lllp_dist);
 
933
 
 
934
        tmp = uint32_compressed_to_str(alloc->num_cpu_groups,
813
935
                                        alloc->cpus_per_node,
814
936
                                        alloc->cpu_count_reps);
815
937
        env_array_overwrite_fmt(dest, "SLURM_JOB_CPUS_PER_NODE", "%s", tmp);
842
964
                xfree(tmp);
843
965
        }
844
966
#endif
 
967
 
 
968
#ifdef HAVE_CRAY_XT
 
969
        select_g_get_jobinfo(alloc->select_jobinfo, SELECT_DATA_RESV_ID,
 
970
                             &resv_id);
 
971
        if (resv_id) {
 
972
                env_array_overwrite_fmt(dest, "BASIL_RESERVATION_ID", "%s",
 
973
                                        resv_id);
 
974
        }
 
975
#endif
 
976
 
845
977
        /* OBSOLETE, but needed by MPI, do not remove */
846
978
        env_array_overwrite_fmt(dest, "SLURM_JOBID", "%u", alloc->job_id);
847
979
        env_array_overwrite_fmt(dest, "SLURM_NNODES", "%u", alloc->node_cnt);
864
996
                   && desc->cpus_per_task != (uint16_t)NO_VAL)
865
997
                        num_tasks /= desc->cpus_per_task;
866
998
                //num_tasks = desc->num_procs;
867
 
        }
 
999
        } 
 
1000
 
 
1001
        if(desc->task_dist == SLURM_DIST_ARBITRARY) {
 
1002
                tmp = desc->req_nodes;
 
1003
                env_array_overwrite_fmt(dest, "SLURM_ARBITRARY_NODELIST",
 
1004
                                        "%s", tmp);
 
1005
        } else
 
1006
                tmp = alloc->node_list;
868
1007
        //info("got %d and %d", num_tasks,  desc->cpus_per_task);
869
 
        step_layout = slurm_step_layout_create(alloc->node_list,
870
 
                                               alloc->cpus_per_node,
871
 
                                               alloc->cpu_count_reps,
872
 
                                               alloc->node_cnt,
873
 
                                               num_tasks,
874
 
                                               desc->cpus_per_task,
875
 
                                               desc->task_dist,
876
 
                                               desc->plane_size);
 
1008
        if(!(step_layout = slurm_step_layout_create(tmp,
 
1009
                                                    alloc->cpus_per_node,
 
1010
                                                    alloc->cpu_count_reps,
 
1011
                                                    alloc->node_cnt,
 
1012
                                                    num_tasks,
 
1013
                                                    desc->cpus_per_task,
 
1014
                                                    desc->task_dist,
 
1015
                                                    desc->plane_size))) 
 
1016
                return SLURM_ERROR;
 
1017
        
 
1018
 
877
1019
        tmp = _uint16_array_to_str(step_layout->node_cnt,
878
1020
                                   step_layout->tasks);
879
1021
        slurm_step_layout_destroy(step_layout);
880
1022
        env_array_overwrite_fmt(dest, "SLURM_TASKS_PER_NODE", "%s", tmp);
881
1023
        xfree(tmp);
 
1024
        return rc;
882
1025
}
883
1026
 
884
1027
/*
904
1047
 *      SLURM_NPROCS
905
1048
 *      SLURM_TASKS_PER_NODE 
906
1049
 */
907
 
extern void
 
1050
extern int
908
1051
env_array_for_batch_job(char ***dest, const batch_job_launch_msg_t *batch,
909
1052
                        const char *node_name)
910
1053
{
911
 
        char *tmp = getenvp(batch->environment, "SLURM_CPUS_PER_TASK");
 
1054
        char *tmp = NULL;
912
1055
        uint32_t num_nodes = 0;
913
1056
        uint32_t num_cpus = 0;
914
1057
        int i;
915
1058
        slurm_step_layout_t *step_layout = NULL;
916
 
        int cpus_per_task = 1;
917
1059
        uint32_t num_tasks = batch->nprocs;
 
1060
        uint16_t cpus_per_task;
 
1061
        uint16_t task_dist;
918
1062
 
919
 
        if(tmp) 
920
 
                cpus_per_task = atoi(tmp);
921
 
        
 
1063
#ifdef HAVE_BG
 
1064
        uint32_t node_cnt = 0;
 
1065
        select_g_get_jobinfo(batch->select_jobinfo, 
 
1066
                             SELECT_DATA_NODE_CNT,
 
1067
                             &node_cnt);
 
1068
        env_array_overwrite_fmt(dest, "SLURM_BG_NUM_NODES", "%u", node_cnt);
 
1069
#endif
922
1070
        /* There is no explicit node count in the batch structure,
923
 
           so we need to calculate the node count. We also need to
924
 
           figure out the explicit cpu count so we can figure out the
925
 
           cpus_per_task. */
 
1071
         * so we need to calculate the node count. */
926
1072
        for (i = 0; i < batch->num_cpu_groups; i++) {
927
1073
                num_nodes += batch->cpu_count_reps[i];
928
1074
                num_cpus += batch->cpu_count_reps[i] * batch->cpus_per_node[i];
931
1077
        env_array_overwrite_fmt(dest, "SLURM_JOB_ID", "%u", batch->job_id);
932
1078
        env_array_overwrite_fmt(dest, "SLURM_JOB_NUM_NODES", "%u", num_nodes);
933
1079
        env_array_overwrite_fmt(dest, "SLURM_JOB_NODELIST", "%s", batch->nodes);
934
 
        tmp = uint32_compressed_to_str((uint32_t)batch->num_cpu_groups,
935
 
                                        batch->cpus_per_node,
936
 
                                        batch->cpu_count_reps);
 
1080
 
 
1081
        tmp = uint32_compressed_to_str(batch->num_cpu_groups,
 
1082
                                       batch->cpus_per_node,
 
1083
                                       batch->cpu_count_reps);
937
1084
        env_array_overwrite_fmt(dest, "SLURM_JOB_CPUS_PER_NODE", "%s", tmp);
938
1085
        xfree(tmp);
939
1086
 
952
1099
        if(num_tasks) 
953
1100
                env_array_overwrite_fmt(dest, "SLURM_NPROCS", "%u", 
954
1101
                                        num_tasks);
955
 
        else 
 
1102
 
 
1103
        if((batch->cpus_per_task != 0) &&
 
1104
           (batch->cpus_per_task != (uint16_t) NO_VAL))
 
1105
                cpus_per_task = batch->cpus_per_task;
 
1106
        else
 
1107
                cpus_per_task = 1;      /* default value */
 
1108
        if (cpus_per_task > 1) {
 
1109
                env_array_overwrite_fmt(dest, "SLURM_CPUS_PER_TASK", "%u",
 
1110
                                        cpus_per_task);
 
1111
        }
 
1112
        
 
1113
        if((tmp = getenvp(*dest, "SLURM_ARBITRARY_NODELIST"))) {
 
1114
                task_dist = SLURM_DIST_ARBITRARY;
 
1115
                num_tasks = batch->nprocs;
 
1116
        } else {
 
1117
                tmp = batch->nodes;
 
1118
                task_dist = SLURM_DIST_BLOCK;
956
1119
                num_tasks = num_cpus / cpus_per_task;
957
 
        
958
 
        step_layout = slurm_step_layout_create(batch->nodes,
959
 
                                               batch->cpus_per_node,
960
 
                                               batch->cpu_count_reps,
961
 
                                               num_nodes,
962
 
                                               num_tasks,
963
 
                                               (uint16_t)cpus_per_task,
964
 
                                               (uint16_t)
965
 
                                               SLURM_DIST_BLOCK,
966
 
                                               (uint16_t)NO_VAL);
 
1120
        }
 
1121
 
 
1122
        if(!(step_layout = slurm_step_layout_create(tmp,
 
1123
                                                    batch->cpus_per_node,
 
1124
                                                    batch->cpu_count_reps,
 
1125
                                                    num_nodes,
 
1126
                                                    num_tasks,
 
1127
                                                    cpus_per_task,
 
1128
                                                    task_dist,
 
1129
                                                    (uint16_t)NO_VAL)))
 
1130
                return SLURM_ERROR;
 
1131
 
967
1132
        tmp = _uint16_array_to_str(step_layout->node_cnt,
968
1133
                                   step_layout->tasks);
969
1134
        slurm_step_layout_destroy(step_layout);
970
1135
        env_array_overwrite_fmt(dest, "SLURM_TASKS_PER_NODE", "%s", tmp);
971
1136
        xfree(tmp);
 
1137
        return SLURM_SUCCESS;
 
1138
 
972
1139
}
973
1140
 
974
1141
/*
976
1143
 * overwriting any environment variables of the same name.  If the address
977
1144
 * pointed to by "dest" is NULL, memory will automatically be xmalloc'ed.
978
1145
 * The array is terminated by a NULL pointer, and thus is suitable for
979
 
 * use by execle() and other env_array_* functions.
 
1146
 * use by execle() and other env_array_* functions.  If preserve_env is
 
1147
 * true, the variables SLURM_NNODES, SLURM_NPROCS and SLURM_TASKS_PER_NODE
 
1148
 * remain unchanged.
980
1149
 *
981
1150
 * Sets variables:
982
1151
 *      SLURM_STEP_ID
983
1152
 *      SLURM_STEP_NUM_NODES
984
1153
 *      SLURM_STEP_NUM_TASKS
985
1154
 *      SLURM_STEP_TASKS_PER_NODE
986
 
 *      SLURM_STEP_LAUNCHER_HOSTNAME
987
1155
 *      SLURM_STEP_LAUNCHER_PORT
988
1156
 *      SLURM_STEP_LAUNCHER_IPADDR
 
1157
 *      SLURM_STEP_RESV_PORTS
989
1158
 *
990
1159
 * Sets OBSOLETE variables:
991
1160
 *      SLURM_STEPID
1000
1169
void
1001
1170
env_array_for_step(char ***dest, 
1002
1171
                   const job_step_create_response_msg_t *step,
1003
 
                   const char *launcher_hostname,
1004
 
                   uint16_t launcher_port)
 
1172
                   uint16_t launcher_port,
 
1173
                   bool preserve_env)
1005
1174
{
1006
1175
        char *tmp;
1007
1176
 
1015
1184
        env_array_overwrite_fmt(dest, "SLURM_STEP_NUM_TASKS",
1016
1185
                                "%u", step->step_layout->task_cnt);
1017
1186
        env_array_overwrite_fmt(dest, "SLURM_STEP_TASKS_PER_NODE", "%s", tmp);
1018
 
        env_array_overwrite_fmt(dest, "SLURM_STEP_LAUNCHER_HOSTNAME",
1019
 
                                "%s", launcher_hostname);
1020
1187
        env_array_overwrite_fmt(dest, "SLURM_STEP_LAUNCHER_PORT",
1021
1188
                                "%hu", launcher_port);
 
1189
        if (step->resv_ports) {
 
1190
                env_array_overwrite_fmt(dest, "SLURM_STEP_RESV_PORTS",
 
1191
                                        "%s", step->resv_ports);
 
1192
        }
1022
1193
 
1023
1194
        /* OBSOLETE, but needed by MPI, do not remove */
1024
1195
        env_array_overwrite_fmt(dest, "SLURM_STEPID", "%u", step->job_step_id);
1025
 
        env_array_overwrite_fmt(dest, "SLURM_NNODES",
1026
 
                                "%hu", step->step_layout->node_cnt);
1027
 
        env_array_overwrite_fmt(dest, "SLURM_NPROCS",
1028
 
                                "%u", step->step_layout->task_cnt);
1029
 
        env_array_overwrite_fmt(dest, "SLURM_TASKS_PER_NODE", "%s", tmp);
 
1196
        if (!preserve_env) {
 
1197
                env_array_overwrite_fmt(dest, "SLURM_NNODES",
 
1198
                                        "%hu", step->step_layout->node_cnt);
 
1199
                env_array_overwrite_fmt(dest, "SLURM_NPROCS",
 
1200
                                        "%u", step->step_layout->task_cnt);
 
1201
                env_array_overwrite_fmt(dest, "SLURM_TASKS_PER_NODE", "%s", 
 
1202
                                        tmp);
 
1203
        }
1030
1204
        env_array_overwrite_fmt(dest, "SLURM_SRUN_COMM_PORT",
1031
1205
                                "%hu", launcher_port);
1032
1206