diff options
author | Thomas White <taw@physics.org> | 2021-07-15 15:13:03 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-07-15 17:05:05 +0200 |
commit | c5a89386f273473954ec5f9e460052c175236c16 (patch) | |
tree | 897babdf9e14812de44260bc5305e55ea4823b7a | |
parent | 81071755af6d46edd21735ecd749b72695629f11 (diff) |
GUI: Run all jobs with same CWD as GUI itself
This requires changing all the paths to relative ones.
Previously, the jobs ran with their CWDs set to the corresponding
"result" folder. The trouble is, this breaks everything that uses a
relative location: image filenames, mask/satmap files referenced by the
geometry, etc.
Note that this change also means that the temporary folders
("indexamajig.XXX") are now produced in the top-level working directory.
Eventually, a GUI option should be added to allow these folders to be
put somewhere better (i.e. somewhere fast).
Closes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/44
-rw-r--r-- | src/crystfel_gui.c | 17 | ||||
-rw-r--r-- | src/crystfel_gui.h | 2 | ||||
-rw-r--r-- | src/gui_ambi.c | 17 | ||||
-rw-r--r-- | src/gui_ambi.h | 7 | ||||
-rw-r--r-- | src/gui_backend_local.c | 159 | ||||
-rw-r--r-- | src/gui_backend_slurm.c | 175 | ||||
-rw-r--r-- | src/gui_index.c | 12 | ||||
-rw-r--r-- | src/gui_index.h | 4 | ||||
-rw-r--r-- | src/gui_merge.c | 45 | ||||
-rw-r--r-- | src/gui_merge.h | 5 |
10 files changed, 267 insertions, 176 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index ff66b6c3..91b91413 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -1500,3 +1500,20 @@ char *make_new_job_title(const char *orig_old_title) return new_title; } } + + +char *relative_to_cwd(GFile *workdir, const char *filename) +{ + GFile *current_dir; + GFile *gfile; + char *rel; + + current_dir = g_file_new_for_path("."); + + gfile = g_file_get_child(workdir, filename); + rel = g_file_get_relative_path(current_dir, gfile); + g_object_unref(gfile); + g_object_unref(current_dir); + + return rel; +} diff --git a/src/crystfel_gui.h b/src/crystfel_gui.h index 868b4cb8..3b2cdacd 100644 --- a/src/crystfel_gui.h +++ b/src/crystfel_gui.h @@ -72,4 +72,6 @@ extern void force_refls_on(struct crystfelproject *proj); extern char *make_new_job_title(const char *old_title); +extern char *relative_to_cwd(GFile *workdir, const char *filename); + #endif diff --git a/src/gui_ambi.c b/src/gui_ambi.c index 6e28f194..fd997a9d 100644 --- a/src/gui_ambi.c +++ b/src/gui_ambi.c @@ -482,7 +482,12 @@ int write_ambigator_script(const char *filename, struct gui_indexing_result *input, const char *n_thread_str, struct ambi_params *params, - const char *out_stream) + const char *out_stream, + const char *stdout_filename, + const char *stderr_filename, + const char *fg_filename, + const char *intermediate_rel_filename, + const char *harvest_filename) { FILE *fh; char *exe_path; @@ -495,13 +500,13 @@ int write_ambigator_script(const char *filename, fprintf(fh, "cat \\\n"); for ( i=0; i<input->n_streams; i++ ) { - fprintf(fh, "\"../%s\" \\\n", input->streams[i]); + fprintf(fh, "\"%s\" \\\n", input->streams[i]); } - fprintf(fh, " > ambigator-input.stream\n"); + fprintf(fh, " > %s\n", intermediate_rel_filename); exe_path = get_crystfel_exe("ambigator"); if ( exe_path == NULL ) return 1; - fprintf(fh, "%s ambigator-input.stream \\\n", exe_path); + fprintf(fh, "%s %s \\\n", exe_path, intermediate_rel_filename); fprintf(fh, " -j %s", n_thread_str); fprintf(fh, " -o \"%s\"", out_stream); @@ -522,8 +527,8 @@ int write_ambigator_script(const char *filename, } fprintf(fh, " --iterations=%i", params->niter); - fprintf(fh, " --fg-graph=fg.dat"); - fprintf(fh, " >stdout.log 2>stderr.log\n"); + fprintf(fh, " --fg-graph=%s", fg_filename); + fprintf(fh, " >%s 2>%s\n", stdout_filename, stderr_filename); fclose(fh); return 0; diff --git a/src/gui_ambi.h b/src/gui_ambi.h index c6b68b35..06bafe64 100644 --- a/src/gui_ambi.h +++ b/src/gui_ambi.h @@ -40,7 +40,12 @@ extern int write_ambigator_script(const char *filename, struct gui_indexing_result *input, const char *n_thread_str, struct ambi_params *params, - const char *out_stream); + const char *out_stream, + const char *stdout_filename, + const char *stderr_filename, + const char *fg_filename, + const char *intermediate_rel_filename, + const char *harvest_filename); extern double read_ambigator_progress(char *logfile_str, int niter); diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index d78fc037..ba56bd7c 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -116,11 +116,7 @@ static int write_file_list(GFile *workdir, if ( fh == NULL ) return 1; for ( i=0; i<n_frames; i++ ) { - if ( filenames[i][0] != '/' ) { - fprintf(fh, "../%s", filenames[i]); - } else { - fprintf(fh, "%s", filenames[i]); - } + fprintf(fh, "%s", filenames[i]); if ( events[i] != NULL ) { fprintf(fh, " %s\n", events[i]); } else { @@ -177,7 +173,7 @@ static struct local_job *start_local_job(char **args, r = g_spawn_async_with_pipes(NULL, args, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - setup_subprocess, workdir_str, + setup_subprocess, NULL, &job->pid, NULL, NULL, &ch_stderr, &error); @@ -387,29 +383,37 @@ static void *run_ambi(const char *job_title, struct local_job *job; struct local_merging_opts *opts = opts_priv; GFile *workdir; - GFile *sc_gfile; - gchar *sc_filename; - GFile *stream_gfile; - char *stream_str; + gchar *sc_rel_filename; + gchar *stream_rel_filename; + gchar *stderr_rel_filename; + gchar *stdout_rel_filename; + gchar *fg_rel_filename; + gchar *intermediate_rel_filename; + gchar *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; - stream_gfile = g_file_get_child(workdir, "ambi.stream"); - stream_str = g_file_get_path(stream_gfile); - g_object_unref(stream_gfile); + stream_rel_filename = relative_to_cwd(workdir, "ambi.stream"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr.log"); + sc_rel_filename = relative_to_cwd(workdir, "run_ambigator.sh"); + fg_rel_filename = relative_to_cwd(workdir, "fg.dat"); + intermediate_rel_filename = relative_to_cwd(workdir, "ambigator-input.stream"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); snprintf(n_thread_str, 64, "%i", opts->n_threads); - sc_gfile = g_file_get_child(workdir, "run_ambigator.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; - if ( !write_ambigator_script(sc_filename, input, n_thread_str, - &proj->ambi_params, stream_str) ) + + if ( !write_ambigator_script(sc_rel_filename, input, n_thread_str, + &proj->ambi_params, stream_rel_filename, + stdout_rel_filename, stderr_rel_filename, + fg_rel_filename, + intermediate_rel_filename, + harvest_rel_filename) ) { char *args[3]; args[0] = "sh"; - args[1] = sc_filename; + args[1] = sc_rel_filename; args[2] = NULL; job = start_local_job(args, job_title, workdir, proj, GUI_JOB_AMBIGATOR); @@ -419,10 +423,18 @@ static void *run_ambi(const char *job_title, } if ( job != NULL ) { - add_indexing_result(proj, job_title, &stream_str, 1); + add_indexing_result(proj, job_title, &stream_rel_filename, 1); } g_object_unref(workdir); + free(sc_rel_filename); + free(stream_rel_filename); + free(stdout_rel_filename); + free(stderr_rel_filename); + free(fg_rel_filename); + free(intermediate_rel_filename); + free(harvest_rel_filename); + return job; } @@ -437,25 +449,32 @@ static void *run_merging(const char *job_title, struct local_job *job; struct local_merging_opts *opts = opts_priv; GFile *workdir; - GFile *sc_gfile; - gchar *sc_filename; + gchar *sc_rel_filename; + gchar *output_rel_filename; + gchar *stderr_rel_filename; + gchar *stdout_rel_filename; + gchar *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; + sc_rel_filename = relative_to_cwd(workdir, "run_merge.sh"); + output_rel_filename = relative_to_cwd(workdir, "crystfel.hkl"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr.log"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); + snprintf(n_thread_str, 63, "%i", opts->n_threads); - sc_gfile = g_file_get_child(workdir, "run_merge.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; - if ( !write_merge_script(sc_filename, input, n_thread_str, - &proj->merging_params, "crystfel.hkl") ) + if ( !write_merge_script(sc_rel_filename, input, n_thread_str, + &proj->merging_params, output_rel_filename, + stdout_rel_filename, stderr_rel_filename, + harvest_rel_filename) ) { char *args[3]; enum gui_job_type type; args[0] = "sh"; - args[1] = sc_filename; + args[1] = sc_rel_filename; args[2] = NULL; if ( strcmp(proj->merging_params.model, "process_hkl") == 0 ) { if ( proj->merging_params.scale ) { @@ -470,34 +489,27 @@ static void *run_merging(const char *job_title, } else { job = NULL; } - g_free(sc_filename); if ( job != NULL ) { - GFile *hkl_gfile; - char *hkl; char *hkl1; char *hkl2; - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl"); - hkl = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); - - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl1"); - hkl1 = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); - - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl2"); - hkl2 = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); + hkl1 = relative_to_cwd(workdir, "crystfel.hkl1"); + hkl2 = relative_to_cwd(workdir, "crystfel.hkl2"); - add_merge_result(proj, job_title, hkl, hkl1, hkl2); - g_free(hkl); + add_merge_result(proj, job_title, output_rel_filename, + hkl1, hkl2); g_free(hkl1); g_free(hkl2); } g_object_unref(workdir); + g_free(sc_rel_filename); + free(output_rel_filename); + free(stdout_rel_filename); + free(stderr_rel_filename); + free(harvest_rel_filename); return job; } @@ -513,9 +525,12 @@ static void *run_indexing(const char *job_title, struct local_job *job; char n_thread_str[64]; GFile *workdir; - GFile *sc_gfile; - gchar *sc_filename; - GFile *stderr_gfile; + gchar *sc_rel_filename; + gchar *stdout_rel_filename; + gchar *stderr_rel_filename; + gchar *files_rel_filename; + gchar *stream_rel_filename; + gchar *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; @@ -530,16 +545,23 @@ static void *run_indexing(const char *job_title, } snprintf(n_thread_str, 63, "%i", opts->n_processes); - sc_gfile = g_file_get_child(workdir, "run_indexamajig.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; - if ( !write_indexamajig_script(sc_filename, + + sc_rel_filename = relative_to_cwd(workdir, "run_indexamajig.sh"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr.log"); + files_rel_filename = relative_to_cwd(workdir, "files.lst"); + stream_rel_filename = relative_to_cwd(workdir, "crystfel.stream"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); + + if ( !write_indexamajig_script(sc_rel_filename, proj->geom_filename, n_thread_str, - "files.lst", - "crystfel.stream", - NULL, 1, + files_rel_filename, + stream_rel_filename, + stdout_rel_filename, + stderr_rel_filename, + harvest_rel_filename, + NULL, &proj->peak_search_params, &proj->indexing_params, wavelength_estimate, @@ -547,7 +569,7 @@ static void *run_indexing(const char *job_title, { char *args[3]; args[0] = "sh"; - args[1] = sc_filename; + args[1] = sc_rel_filename; args[2] = NULL; job = start_local_job(args, job_title, workdir, proj, GUI_JOB_INDEXING); @@ -557,23 +579,20 @@ static void *run_indexing(const char *job_title, if ( job != NULL ) { - char *stream_fn; - /* Indexing-specific job data */ job->n_frames = proj->n_frames; + job->stderr_filename = strdup(stderr_rel_filename); + add_indexing_result(proj, job_title, &stream_rel_filename, 1); - stderr_gfile = g_file_get_child(workdir, "stderr.log"); - job->stderr_filename = g_file_get_path(stderr_gfile); - g_object_unref(stderr_gfile); - - GFile *stream_gfile = g_file_get_child(job->workdir, - "crystfel.stream"); - stream_fn = g_file_get_path(stream_gfile); - g_object_unref(stream_gfile); - add_indexing_result(proj, job_title, &stream_fn, 1); - g_free(stream_fn); + } else { } g_object_unref(workdir); + free(sc_rel_filename); + free(files_rel_filename); + free(stream_rel_filename); + free(stdout_rel_filename); + free(stderr_rel_filename); + free(harvest_rel_filename); return job; } diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index e0f74b10..d07675be 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -172,13 +172,10 @@ static double indexing_progress(struct slurm_job *job, int *running) for ( i=0; i<job->n_blocks; i++ ) { char tmp[128]; - GFile *stderr_gfile; char *stderr_filename; snprintf(tmp, 127, "stderr-%i.log", i); - stderr_gfile = g_file_get_child(job->workdir, tmp); - stderr_filename = g_file_get_path(stderr_gfile); - g_object_unref(stderr_gfile); + stderr_filename = relative_to_cwd(job->workdir, tmp); n_proc += read_number_processed(stderr_filename); g_free(stderr_filename); @@ -469,8 +466,8 @@ static struct slurm_job *start_slurm_job(enum gui_job_type type, struct slurm_job *job; job_desc_msg_t job_desc_msg; submit_response_msg_t *resp; - GFile *stderr_gfile; int r; + GFile *cwd_gfile; script = load_entire_file(script_filename); if ( script == NULL ) return NULL; @@ -483,6 +480,8 @@ static struct slurm_job *start_slurm_job(enum gui_job_type type, job->type = type; + cwd_gfile = g_file_new_for_path("."); + env = create_env(&n_env, NULL); slurm_init_job_desc_msg(&job_desc_msg); @@ -499,7 +498,7 @@ static struct slurm_job *start_slurm_job(enum gui_job_type type, job_desc_msg.name = safe_strdup(jobname); job_desc_msg.std_err = strdup(stderr_filename); job_desc_msg.std_out = strdup(stdout_filename); - job_desc_msg.work_dir = g_file_get_path(workdir); + job_desc_msg.work_dir = g_file_get_path(cwd_gfile); job_desc_msg.script = script; job_desc_msg.environment = env; job_desc_msg.env_size = n_env; @@ -507,6 +506,8 @@ static struct slurm_job *start_slurm_job(enum gui_job_type type, job_desc_msg.account = safe_strdup(opts->account); job_desc_msg.array_inx = safe_strdup(array_inx); + g_object_unref(cwd_gfile); + r = slurm_submit_batch_job(&job_desc_msg, &resp); free(job_desc_msg.mail_user); free(job_desc_msg.partition); @@ -529,10 +530,7 @@ static struct slurm_job *start_slurm_job(enum gui_job_type type, job->job_id = resp->job_id; slurm_free_submit_response_response_msg(resp); - stderr_gfile = g_file_get_child(workdir, stderr_filename); - job->stderr_filename = g_file_get_path(stderr_gfile); - g_object_unref(stderr_gfile); - + job->stderr_filename = strdup(stderr_filename); job->workdir = g_file_dup(workdir); return job; @@ -560,11 +558,7 @@ static void write_partial_file_list(GFile *workdir, (i<(j+1)*block_size) && (i<n_frames); i++ ) { - if ( filenames[i][0] != '/' ) { - fprintf(fh, "../%s", filenames[i]); - } else { - fprintf(fh, "%s", filenames[i]); - } + fprintf(fh, "%s", filenames[i]); if ( events[i] != NULL ) { fprintf(fh, " %s\n", events[i]); } else { @@ -590,11 +584,15 @@ static void *run_indexing(const char *job_title, int i; char **streams; GFile *workdir; - GFile *sc_gfile; - char *sc_filename; int n_blocks; char array_inx[128]; char serial_offs[128]; + gchar *sc_rel_filename; + gchar *stdout_rel_filename; + gchar *stderr_rel_filename; + gchar *files_rel_filename; + gchar *stream_rel_filename; + gchar *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; @@ -611,7 +609,6 @@ static void *run_indexing(const char *job_title, char file_list[128]; char stream_filename[128]; - GFile *stream_gfile; /* Create (sub-)list of files */ snprintf(file_list, 127, "files-%i.lst", i); @@ -625,44 +622,46 @@ static void *run_indexing(const char *job_title, /* Work out the stream filename */ snprintf(stream_filename, 127, "crystfel-%i.stream", i); - stream_gfile = g_file_get_child(workdir, - stream_filename); - streams[i] = g_file_get_path(stream_gfile); - g_object_unref(stream_gfile); + streams[i] = relative_to_cwd(workdir, stream_filename); } - sc_gfile = g_file_get_child(workdir, "run_indexamajig.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; - snprintf(array_inx, 127, "0-%i", n_blocks-1); snprintf(serial_offs, 127, "$((${SLURM_ARRAY_TASK_ID}*%i+1))", opts->block_size); - if ( !write_indexamajig_script(sc_filename, + sc_rel_filename = relative_to_cwd(workdir, "run_indexamajig.sh"); + files_rel_filename = relative_to_cwd(workdir, + "files-${SLURM_ARRAY_TASK_ID}.lst"); + stream_rel_filename = relative_to_cwd(workdir, + "crystfel-${SLURM_ARRAY_TASK_ID}.stream"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout-%a.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr-%a.log"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); + + if ( !write_indexamajig_script(sc_rel_filename, proj->geom_filename, "`nproc`", - "files-${SLURM_ARRAY_TASK_ID}.lst", - "crystfel-${SLURM_ARRAY_TASK_ID}.stream", - serial_offs, 0, + files_rel_filename, + stream_rel_filename, + NULL, NULL, + harvest_rel_filename, + serial_offs, &proj->peak_search_params, &proj->indexing_params, wavelength_estimate, clen_estimate) ) { job = start_slurm_job(GUI_JOB_INDEXING, - sc_filename, + sc_rel_filename, job_title, array_inx, workdir, - "stdout-%a.log", - "stderr-%a.log", + stdout_rel_filename, + stderr_rel_filename, &opts->common); } else { job = NULL; } - g_free(sc_filename); if ( job != NULL ) { job->n_frames = proj->n_frames; @@ -675,6 +674,12 @@ static void *run_indexing(const char *job_title, } free(streams); + free(sc_rel_filename); + free(files_rel_filename); + free(stream_rel_filename); + free(stdout_rel_filename); + free(stderr_rel_filename); + free(harvest_rel_filename); g_object_unref(workdir); return job; @@ -856,37 +861,47 @@ static void *run_ambi(const char *job_title, struct slurm_job *job; struct slurm_ambi_opts *opts = opts_priv; GFile *workdir; - GFile *sc_gfile; - char *sc_filename; - GFile *stream_gfile; - char *stream_str; + char *sc_rel_filename; + char *stream_rel_filename; + char *stdout_rel_filename; + char *stderr_rel_filename; + char *fg_rel_filename; + char *intermediate_rel_filename; + char *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; - stream_gfile = g_file_get_child(workdir, "ambi.stream"); - stream_str = g_file_get_path(stream_gfile); - g_object_unref(stream_gfile); - - sc_gfile = g_file_get_child(workdir, "run_ambigator.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; - - if ( !write_ambigator_script(sc_filename, input, "`nproc`", - &proj->ambi_params, stream_str) ) + stream_rel_filename = relative_to_cwd(workdir, "ambi.stream"); + sc_rel_filename = relative_to_cwd(workdir, "run_ambigator.sh"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr.log"); + fg_rel_filename = relative_to_cwd(workdir, "fg.dat"); + intermediate_rel_filename = relative_to_cwd(workdir, "ambigator-input.stream"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); + + if ( !write_ambigator_script(sc_rel_filename, input, "`nproc`", + &proj->ambi_params, stream_rel_filename, + stdout_rel_filename, stderr_rel_filename, + fg_rel_filename, + intermediate_rel_filename, + harvest_rel_filename) ) { job = start_slurm_job(GUI_JOB_AMBIGATOR, - sc_filename, job_title, NULL, workdir, - "stdout.log", "stderr.log", &opts->common); + sc_rel_filename, job_title, NULL, workdir, + stdout_rel_filename, stderr_rel_filename, + &opts->common); job->niter = proj->ambi_params.niter; } else { job = NULL; } - g_free(sc_filename); + g_free(sc_rel_filename); + g_free(stdout_rel_filename); + g_free(stderr_rel_filename); + g_free(harvest_rel_filename); if ( job != NULL ) { - add_indexing_result(proj, job_title, &stream_str, 1); + add_indexing_result(proj, job_title, &stream_rel_filename, 1); } g_object_unref(workdir); @@ -903,19 +918,25 @@ static void *run_merging(const char *job_title, struct slurm_job *job; struct slurm_merging_opts *opts = opts_priv; GFile *workdir; - GFile *sc_gfile; - char *sc_filename; + char *sc_rel_filename; + char *output_rel_filename; + char *stdout_rel_filename; + char *stderr_rel_filename; + char *harvest_rel_filename; workdir = make_job_folder(job_title, job_notes); if ( workdir == NULL ) return NULL; - sc_gfile = g_file_get_child(workdir, "run_merge.sh"); - sc_filename = g_file_get_path(sc_gfile); - g_object_unref(sc_gfile); - if ( sc_filename == NULL ) return NULL; + sc_rel_filename = relative_to_cwd(workdir, "run_merge.sh"); + output_rel_filename = relative_to_cwd(workdir, "crystfel.hkl"); + stdout_rel_filename = relative_to_cwd(workdir, "stdout.log"); + stderr_rel_filename = relative_to_cwd(workdir, "stderr.log"); + harvest_rel_filename = relative_to_cwd(workdir, "parameters.json"); - if ( !write_merge_script(sc_filename, input, "`nproc`", - &proj->merging_params, "crystfel.hkl") ) + if ( !write_merge_script(sc_rel_filename, input, "`nproc`", + &proj->merging_params, output_rel_filename, + stdout_rel_filename, stderr_rel_filename, + harvest_rel_filename) ) { enum gui_job_type type; if ( strcmp(proj->merging_params.model, "process_hkl") == 0 ) { @@ -927,40 +948,34 @@ static void *run_merging(const char *job_title, } else { type = GUI_JOB_PARTIALATOR; } - job = start_slurm_job(type, sc_filename, job_title, NULL, - workdir, "stdout.log", "stderr.log", + job = start_slurm_job(type, sc_rel_filename, job_title, NULL, + workdir, stdout_rel_filename, + stderr_rel_filename, &opts->common); } else { job = NULL; } - g_free(sc_filename); if ( job != NULL ) { - GFile *hkl_gfile; - char *hkl; char *hkl1; char *hkl2; - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl"); - hkl = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); - - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl1"); - hkl1 = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); - - hkl_gfile = g_file_get_child(workdir, "crystfel.hkl2"); - hkl2 = g_file_get_path(hkl_gfile); - g_object_unref(hkl_gfile); + hkl1 = relative_to_cwd(workdir, "crystfel.hkl1"); + hkl2 = relative_to_cwd(workdir, "crystfel.hkl2"); - add_merge_result(proj, job_title, hkl, hkl1, hkl2); - g_free(hkl); + add_merge_result(proj, job_title, output_rel_filename, + hkl1, hkl2); g_free(hkl1); g_free(hkl2); } g_object_unref(workdir); + g_free(sc_rel_filename); + g_free(stdout_rel_filename); + g_free(stderr_rel_filename); + g_free(output_rel_filename); + g_free(harvest_rel_filename); return job; } diff --git a/src/gui_index.c b/src/gui_index.c index ad1206e0..645af05e 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -811,6 +811,7 @@ static char **indexamajig_command_line(const char *geom_filename, const char *n_thread_str, const char *files_list, const char *stream_filename, + const char *harvest_filename, const char *serial_start, struct peak_params *peak_search_params, struct index_params *indexing_params, @@ -975,7 +976,7 @@ static char **indexamajig_command_line(const char *geom_filename, add_arg_string(args, n_args++, "serial-start", serial_start); } - add_arg_string(args, n_args++, "harvest-file", "parameters.json"); + add_arg_string(args, n_args++, "harvest-file", harvest_filename); args[n_args] = NULL; return args; @@ -1022,8 +1023,10 @@ int write_indexamajig_script(const char *script_filename, const char *n_thread_str, const char *files_list, const char *stream_filename, + const char *stdout_filename, + const char *stderr_filename, + const char *harvest_filename, const char *serial_start, - int redirect_output, struct peak_params *peak_search_params, struct index_params *indexing_params, double wavelength_estimate, @@ -1037,6 +1040,7 @@ int write_indexamajig_script(const char *script_filename, n_thread_str, files_list, stream_filename, + harvest_filename, serial_start, peak_search_params, indexing_params, @@ -1056,8 +1060,8 @@ int write_indexamajig_script(const char *script_filename, i++; }; free(cmdline); - if ( redirect_output ) { - fprintf(fh, ">stdout.log 2>stderr.log\n"); + if ( stdout_filename != NULL ) { + fprintf(fh, ">%s 2>%s\n", stdout_filename, stderr_filename); } fclose(fh); diff --git a/src/gui_index.h b/src/gui_index.h index 991ba08e..b2b18939 100644 --- a/src/gui_index.h +++ b/src/gui_index.h @@ -48,8 +48,10 @@ extern int write_indexamajig_script(const char *script_filename, const char *n_thread_str, const char *files_list, const char *stream_filename, + const char *stdout_filename, + const char *stderr_filename, + const char *harvest_filename, const char *serial_start, - int redirect_output, struct peak_params *peak_search_params, struct index_params *indexing_params, double wavelength_estimate, diff --git a/src/gui_merge.c b/src/gui_merge.c index bef6d7b7..b911fa5a 100644 --- a/src/gui_merge.c +++ b/src/gui_merge.c @@ -349,7 +349,10 @@ static int write_partialator_script(const char *filename, struct gui_indexing_result *input, const char *n_thread_str, struct merging_params *params, - const char *out_hkl) + const char *out_hkl, + const char *stdout_filename, + const char *stderr_filename, + const char *harvest_filename) { FILE *fh; char *exe_path; @@ -365,7 +368,7 @@ static int write_partialator_script(const char *filename, fprintf(fh, "%s \\\n", exe_path); for ( i=0; i<input->n_streams; i++ ) { - fprintf(fh, "\"../%s\" \\\n", input->streams[i]); + fprintf(fh, "\"%s\" \\\n", input->streams[i]); } fprintf(fh, " --model=%s", params->model); @@ -405,9 +408,9 @@ static int write_partialator_script(const char *filename, } fprintf(fh, " --iterations=%i", params->niter); - fprintf(fh, " --harvest-file=parameters.json"); + fprintf(fh, " --harvest-file=%s", harvest_filename); - fprintf(fh, " >stdout.log 2>stderr.log\n"); + fprintf(fh, " >%s 2>%s\n", stdout_filename, stderr_filename); fclose(fh); return 0; @@ -419,6 +422,8 @@ static void add_process_hkl(FILE *fh, struct gui_indexing_result *input, struct merging_params *params, const char *out_hkl, + const char *stdout_filename, + const char *stderr_filename, const char *extra_arg, const char *out_suffix) { @@ -427,7 +432,7 @@ static void add_process_hkl(FILE *fh, fprintf(fh, "%s \\\n", exe_path); for ( i=0; i<input->n_streams; i++ ) { - fprintf(fh, " \"../%s\" \\\n", input->streams[i]); + fprintf(fh, " \"%s\" \\\n", input->streams[i]); } fprintf(fh, " -o \"%s%s\"", out_hkl, out_suffix); @@ -442,14 +447,17 @@ static void add_process_hkl(FILE *fh, fprintf(fh, " --max-adu=%f", params->max_adu); fprintf(fh, " --min-res=%f", params->min_res); fprintf(fh, " --push-res=%f", params->push_res); - fprintf(fh, " %s >>stdout.log 2>>stderr.log\n", extra_arg); + fprintf(fh, " %s >>%s 2>>%s\n", + extra_arg, stdout_filename, stderr_filename); } static int write_process_hkl_script(const char *filename, struct gui_indexing_result *input, struct merging_params *params, - const char *out_hkl) + const char *out_hkl, + const char *stdout_filename, + const char *stderr_filename) { FILE *fh; char *exe_path; @@ -462,9 +470,12 @@ static int write_process_hkl_script(const char *filename, exe_path = get_crystfel_exe("process_hkl"); if ( exe_path == NULL ) return 1; - add_process_hkl(fh, exe_path, input, params, out_hkl, "", ""); - add_process_hkl(fh, exe_path, input, params, out_hkl, "--even-only", "1"); - add_process_hkl(fh, exe_path, input, params, out_hkl, "--odd-only", "2"); + add_process_hkl(fh, exe_path, input, params, out_hkl, + stdout_filename, stderr_filename, "", ""); + add_process_hkl(fh, exe_path, input, params, out_hkl, + stdout_filename, stderr_filename, "--even-only", "1"); + add_process_hkl(fh, exe_path, input, params, out_hkl, + stdout_filename, stderr_filename, "--odd-only", "2"); fclose(fh); return 0; @@ -475,14 +486,22 @@ int write_merge_script(const char *filename, struct gui_indexing_result *input, const char *n_thread_str, struct merging_params *params, - const char *out_hkl) + const char *out_hkl, + const char *stdout_filename, + const char *stderr_filename, + const char *harvest_filename) { if ( strcmp(params->model, "process_hkl") == 0 ) { return write_process_hkl_script(filename, input, - params, out_hkl); + params, out_hkl, + stdout_filename, + stderr_filename); } else { return write_partialator_script(filename, input, n_thread_str, - params, out_hkl); + params, out_hkl, + stdout_filename, + stderr_filename, + harvest_filename); } } diff --git a/src/gui_merge.h b/src/gui_merge.h index e3f947c7..36b077aa 100644 --- a/src/gui_merge.h +++ b/src/gui_merge.h @@ -41,7 +41,10 @@ extern int write_merge_script(const char *filename, struct gui_indexing_result *input, const char *n_thread_str, struct merging_params *params, - const char *out_hkl); + const char *out_hkl, + const char *stdout_filename, + const char *stderr_filename, + const char *harvest_filename); extern double read_merge_progress(const char *logfile_str, enum gui_job_type type); |