~ubuntu-branches/ubuntu/saucy/slurm-llnl/saucy

« back to all changes in this revision

Viewing changes to src/common/env.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2008-12-03 11:56:28 UTC
  • mfrom: (1.1.8 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20081203115628-93t417da6wkazmo5
Tags: 1.3.11-1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
740
740
 * array.  Free with xfree().
741
741
 */
742
742
extern char *uint32_compressed_to_str(uint32_t array_len,
743
 
                                       const uint32_t *array,
744
 
                                       const uint32_t *array_reps)
 
743
                                      const uint32_t *array,
 
744
                                      const uint32_t *array_reps)
745
745
{
746
746
        int i;
747
747
        char *sep = ","; /* seperator */
784
784
 */
785
785
void
786
786
env_array_for_job(char ***dest, const resource_allocation_response_msg_t *alloc,
787
 
                  job_desc_msg_t *desc)
 
787
                  const job_desc_msg_t *desc)
788
788
{
789
789
        char *bgl_part_id = NULL, *tmp;
790
790
        slurm_step_layout_t *step_layout = NULL;
822
822
        env_array_overwrite_fmt(dest, "SLURM_NNODES", "%u", alloc->node_cnt);
823
823
        env_array_overwrite_fmt(dest, "SLURM_NODELIST", "%s", alloc->node_list);
824
824
        
825
 
        if(num_tasks == NO_VAL) 
826
 
                num_tasks = desc->num_procs;
 
825
        if(num_tasks == NO_VAL) {
 
826
                /* If we know how many tasks we are going to do then
 
827
                   we set SLURM_TASKS_PER_NODE */
 
828
                int i=0;
 
829
                /* If no tasks were given we can figure it out here
 
830
                 * by totalling up the cpus and then dividing by the
 
831
                 * number of cpus per task */
 
832
                
 
833
                num_tasks = 0;
 
834
                for (i = 0; i < alloc->num_cpu_groups; i++) {
 
835
                        num_tasks += alloc->cpu_count_reps[i] 
 
836
                                * alloc->cpus_per_node[i];
 
837
                }
 
838
                if((int)desc->cpus_per_task > 1 
 
839
                   && desc->cpus_per_task != (uint16_t)NO_VAL)
 
840
                        num_tasks /= desc->cpus_per_task;
 
841
                //num_tasks = desc->num_procs;
 
842
        }
 
843
        //info("got %d and %d", num_tasks,  desc->cpus_per_task);
827
844
        step_layout = slurm_step_layout_create(alloc->node_list,
828
845
                                               alloc->cpus_per_node,
829
846
                                               alloc->cpu_count_reps,
830
847
                                               alloc->node_cnt,
831
848
                                               num_tasks,
 
849
                                               desc->cpus_per_task,
832
850
                                               desc->task_dist,
833
851
                                               desc->plane_size);
834
852
        tmp = _uint16_array_to_str(step_layout->node_cnt,
865
883
env_array_for_batch_job(char ***dest, const batch_job_launch_msg_t *batch,
866
884
                        const char *node_name)
867
885
{
868
 
        char *tmp;
 
886
        char *tmp = getenvp(batch->environment, "SLURM_CPUS_PER_TASK");
869
887
        uint32_t num_nodes = 0;
 
888
        uint32_t num_cpus = 0;
870
889
        int i;
871
890
        slurm_step_layout_t *step_layout = NULL;
 
891
        int cpus_per_task = 1;
 
892
        uint32_t num_tasks = batch->nprocs;
872
893
 
873
 
        /* there is no explicit node count in the batch structure,
874
 
           so we need to calculate the node count */
 
894
        if(tmp) 
 
895
                cpus_per_task = atoi(tmp);
 
896
        
 
897
        /* There is no explicit node count in the batch structure,
 
898
           so we need to calculate the node count. We also need to
 
899
           figure out the explicit cpu count so we can figure out the
 
900
           cpus_per_task. */
875
901
        for (i = 0; i < batch->num_cpu_groups; i++) {
876
902
                num_nodes += batch->cpu_count_reps[i];
 
903
                num_cpus += batch->cpu_count_reps[i] * batch->cpus_per_node[i];
877
904
        }
878
905
 
879
906
        env_array_overwrite_fmt(dest, "SLURM_JOB_ID", "%u", batch->job_id);
883
910
                                        batch->cpus_per_node,
884
911
                                        batch->cpu_count_reps);
885
912
        env_array_overwrite_fmt(dest, "SLURM_JOB_CPUS_PER_NODE", "%s", tmp);
 
913
        xfree(tmp);
886
914
 
887
915
        env_array_overwrite_fmt(dest, "ENVIRONMENT", "BATCH");
888
916
        if (node_name)
896
924
        env_array_overwrite_fmt(dest, "SLURM_JOBID", "%u", batch->job_id);
897
925
        env_array_overwrite_fmt(dest, "SLURM_NNODES", "%u", num_nodes);
898
926
        env_array_overwrite_fmt(dest, "SLURM_NODELIST", "%s", batch->nodes);
899
 
        if(batch->nprocs) {
900
 
                xfree(tmp);
 
927
        if(num_tasks) 
901
928
                env_array_overwrite_fmt(dest, "SLURM_NPROCS", "%u", 
902
 
                                        batch->nprocs);
903
 
                step_layout = slurm_step_layout_create(batch->nodes,
904
 
                                                       batch->cpus_per_node,
905
 
                                                       batch->cpu_count_reps,
906
 
                                                       num_nodes,
907
 
                                                       batch->nprocs,
908
 
                                                       (uint16_t)
909
 
                                                       SLURM_DIST_BLOCK,
910
 
                                                       (uint16_t)NO_VAL);
911
 
                tmp = _uint16_array_to_str(step_layout->node_cnt,
912
 
                                           step_layout->tasks);
913
 
                slurm_step_layout_destroy(step_layout);
914
 
        }
 
929
                                        num_tasks);
 
930
        else 
 
931
                num_tasks = num_cpus / cpus_per_task;
 
932
        
 
933
        step_layout = slurm_step_layout_create(batch->nodes,
 
934
                                               batch->cpus_per_node,
 
935
                                               batch->cpu_count_reps,
 
936
                                               num_nodes,
 
937
                                               num_tasks,
 
938
                                               (uint16_t)cpus_per_task,
 
939
                                               (uint16_t)
 
940
                                               SLURM_DIST_BLOCK,
 
941
                                               (uint16_t)NO_VAL);
 
942
        tmp = _uint16_array_to_str(step_layout->node_cnt,
 
943
                                   step_layout->tasks);
 
944
        slurm_step_layout_destroy(step_layout);
915
945
        env_array_overwrite_fmt(dest, "SLURM_TASKS_PER_NODE", "%s", tmp);
916
946
        xfree(tmp);
917
947
}