コード例 #1
0
ファイル: sh5util.c プロジェクト: jsollom/slurm
static void _merge_step_files(void)
{
	hid_t 	fid_job = -1, jgid_step = -1, jgid_nodes = -1, jgid_tasks = -1;
	DIR    *dir;
	struct  dirent *de;
	char	file_name[MAX_PROFILE_PATH+1];
	char	step_dir[MAX_PROFILE_PATH+1];
	char	step_path[MAX_PROFILE_PATH+1];
	char	jgrp_step_name[MAX_GROUP_NAME+1];
	char	jgrp_nodes_name[MAX_GROUP_NAME+1];
	char	jgrp_tasks_name[MAX_GROUP_NAME+1];
	char 	*step_node, *pos_char, *stepno;
	int	stepx = 0, num_steps = 0, nodex = -1, max_step = -1;
	int	jobid, stepid;
	bool	found_files = false;

	sprintf(step_dir, "%s/%s", params.dir, params.user);
	while (max_step == -1 || stepx <= max_step) {
		if (!(dir = opendir(step_dir))) {
			error("opendir for job profile directory: %m");
			exit(1);
		}
		nodex = 0;
		while ((de = readdir(dir))) {
			strcpy(file_name, de->d_name);
			if (file_name[0] == '.')
				continue; // Not HDF5 file
			pos_char = strstr(file_name,".h5");
			if (!pos_char) {
				error("error processing this file, %s, "
				      "(not .h5)", de->d_name);
				continue; // Not HDF5 file
			}
			*pos_char = 0; // truncate .hf
			pos_char = strchr(file_name,'_');
			if (!pos_char)
				continue; // not right format
			*pos_char = 0; // make jobid string
			jobid = strtol(file_name, NULL, 10);
			if (jobid != params.job_id)
				continue; // not desired job
			stepno = pos_char + 1;
			pos_char = strchr(stepno,'_');
			if (!pos_char) {
				continue; // not right format
			}
			*pos_char = 0; // make stepid string
			stepid = strtol(stepno, NULL, 10);
			if (stepid > max_step)
				max_step = stepid;
			if (stepid != stepx)
				continue; // Not step we are merging
			step_node = pos_char + 1;
			// Found a node step file for this job
			if (!found_files) {
				// Need to create the job file
				fid_job = H5Fcreate(params.output,
						    H5F_ACC_TRUNC,
						    H5P_DEFAULT,
						    H5P_DEFAULT);
				if (fid_job < 0) {
					fatal("Failed to %s %s",
					      "create HDF5 file:",
					      params.output);
				}
				found_files = true;
			}
			if (nodex == 0) {
				num_steps++;
				sprintf(jgrp_step_name, "/%s_%d", GRP_STEP,
					stepx);
				jgid_step = make_group(fid_job, jgrp_step_name);
				if (jgid_step < 0) {
					error("Failed to create %s",
					      jgrp_step_name);
					continue;
				}
				sprintf(jgrp_nodes_name,"%s/%s",
					jgrp_step_name,
					GRP_NODES);
				jgid_nodes = make_group(jgid_step,
							jgrp_nodes_name);
				if (jgid_nodes < 0) {
					error("Failed to create %s",
					      jgrp_nodes_name);
					continue;
				}
				sprintf(jgrp_tasks_name,"%s/%s",
					jgrp_step_name,
					GRP_TASKS);
				jgid_tasks = make_group(jgid_step,
							jgrp_tasks_name);
				if (jgid_tasks < 0) {
					error("Failed to create %s",
					      jgrp_tasks_name);
					continue;
				}
			}
			sprintf(step_path, "%s/%s", step_dir, de->d_name);
			debug("Adding %s to the job file", step_path);
			_merge_node_step_data(fid_job, step_path,
					      nodex, step_node,
					      jgid_nodes, jgid_tasks);
			nodex++;
		}
		closedir(dir);
		if (nodex > 0) {
			put_int_attribute(jgid_step, ATTR_NNODES, nodex);
			H5Gclose(jgid_tasks);
			H5Gclose(jgid_nodes);
			H5Gclose(jgid_step);
		}
		stepx++;
	}
	if (!found_files)
		info("No node-step files found for jobid=%d", params.job_id);
	else
		put_int_attribute(fid_job, ATTR_NSTEPS, num_steps);
	if (fid_job != -1)
		H5Fclose(fid_job);
}
コード例 #2
0
ファイル: sh5util.c プロジェクト: FredHutch/slurm
static int _merge_step_files(void)
{
	hid_t fid_job = -1;
	hid_t jgid_step = -1;
	hid_t jgid_nodes = -1;
	hid_t jgid_tasks = -1;
	DIR *dir;
	struct  dirent *de;
	char file_name[MAX_PROFILE_PATH+1];
	char step_dir[MAX_PROFILE_PATH+1];
	char step_path[MAX_PROFILE_PATH+1];
	char jgrp_step_name[MAX_GROUP_NAME+1];
	char jgrp_nodes_name[MAX_GROUP_NAME+1];
	char jgrp_tasks_name[MAX_GROUP_NAME+1];
	char *step_node;
	char *pos_char;
	char *stepno;
	int	stepx = 0;
	int num_steps = 0;
	int nodex = -1;
	int max_step = -1;
	int	jobid, stepid;
	bool found_files = false;

	sprintf(step_dir, "%s/%s", params.dir, params.user);

	while (max_step == -1 || stepx <= max_step) {

		if (!(dir = opendir(step_dir))) {
			error("Cannot open %s job profile directory: %m", step_dir);
			return -1;
		}

		nodex = 0;
		while ((de = readdir(dir))) {

			strcpy(file_name, de->d_name);
			if (file_name[0] == '.')
				continue;

			pos_char = strstr(file_name,".h5");
			if (!pos_char)
				continue;
			*pos_char = 0;

			pos_char = strchr(file_name,'_');
			if (!pos_char)
				continue;
			*pos_char = 0;

			jobid = strtol(file_name, NULL, 10);
			if (jobid != params.job_id)
				continue;

			stepno = pos_char + 1;
			pos_char = strchr(stepno,'_');
			if (!pos_char) {
				continue;
			}
			*pos_char = 0;

			stepid = strtol(stepno, NULL, 10);
			if (stepid > max_step)
				max_step = stepid;
			if (stepid != stepx)
				continue;

			step_node = pos_char + 1;

			if (!found_files) {
				fid_job = H5Fcreate(params.output,
				                    H5F_ACC_TRUNC,
				                    H5P_DEFAULT,
				                    H5P_DEFAULT);
				if (fid_job < 0) {
					error("Failed create HDF5 file %s", params.output);
					return -1;
				}
				found_files = true;
			}

			if (nodex == 0) {

				num_steps++;
				sprintf(jgrp_step_name, "/%s_%d", GRP_STEP,
				        stepx);

				jgid_step = make_group(fid_job, jgrp_step_name);
				if (jgid_step < 0) {
					error("Failed to create %s", jgrp_step_name);
					continue;
				}

				sprintf(jgrp_nodes_name,"%s/%s",
				        jgrp_step_name,
				        GRP_NODES);
				jgid_nodes = make_group(jgid_step,
				                        jgrp_nodes_name);
				if (jgid_nodes < 0) {
					error("Failed to create %s", jgrp_nodes_name);
					continue;
				}

				sprintf(jgrp_tasks_name,"%s/%s",
				        jgrp_step_name,
				        GRP_TASKS);
				jgid_tasks = make_group(jgid_step,
				                        jgrp_tasks_name);
				if (jgid_tasks < 0) {
					error("Failed to create %s", jgrp_tasks_name);
					continue;
				}
			}

			sprintf(step_path, "%s/%s", step_dir, de->d_name);
			debug("Adding %s to the job file", step_path);
			_merge_node_step_data(fid_job, step_path,
			                      nodex, step_node,
			                      jgid_nodes, jgid_tasks);
			nodex++;
		}

		closedir(dir);

		if (nodex > 0) {
			put_int_attribute(jgid_step, ATTR_NNODES, nodex);
			H5Gclose(jgid_tasks);
			H5Gclose(jgid_nodes);
			H5Gclose(jgid_step);
		}

		/* If we did not find the step 0
		 * bail out.
		 */
		if (stepx == 0
			&& !found_files)
			break;

		stepx++;
	}

	if (!found_files)
		info("No node-step files found for jobid %d", params.job_id);
	else
		put_int_attribute(fid_job, ATTR_NSTEPS, num_steps);

	if (fid_job != -1)
		H5Fclose(fid_job);

	return 0;
}