void print_lambda_matrix (FILE * outfile, lambda_matrix matrix, int m, int n) { int i; for (i = 0; i < m; i++) print_lambda_vector (outfile, matrix[i], n); fprintf (outfile, "\n"); }
extern FILE *open_dhdl(const char *filename, const t_inputrec *ir, const gmx_output_env_t *oenv) { FILE *fp; const char *dhdl = "dH/d\\lambda", *deltag = "\\DeltaH", *lambda = "\\lambda", *lambdastate = "\\lambda state"; char title[STRLEN], label_x[STRLEN], label_y[STRLEN]; int i, nps, nsets, nsets_de, nsetsbegin; int n_lambda_terms = 0; t_lambda *fep = ir->fepvals; /* for simplicity */ t_expanded *expand = ir->expandedvals; char **setname; char buf[STRLEN], lambda_vec_str[STRLEN], lambda_name_str[STRLEN]; int bufplace = 0; int nsets_dhdl = 0; int s = 0; int nsetsextend; gmx_bool write_pV = FALSE; /* count the number of different lambda terms */ for (i = 0; i < efptNR; i++) { if (fep->separate_dvdl[i]) { n_lambda_terms++; } } if (fep->n_lambda == 0) { sprintf(title, "%s", dhdl); sprintf(label_x, "Time (ps)"); sprintf(label_y, "%s (%s %s)", dhdl, unit_energy, "[\\lambda]\\S-1\\N"); } else { sprintf(title, "%s and %s", dhdl, deltag); sprintf(label_x, "Time (ps)"); sprintf(label_y, "%s and %s (%s %s)", dhdl, deltag, unit_energy, "[\\8l\\4]\\S-1\\N"); } fp = gmx_fio_fopen(filename, "w+"); xvgr_header(fp, title, label_x, label_y, exvggtXNY, oenv); if (!(ir->bSimTemp)) { bufplace = sprintf(buf, "T = %g (K) ", ir->opts.ref_t[0]); } if ((ir->efep != efepSLOWGROWTH) && (ir->efep != efepEXPANDED)) { if ( (fep->init_lambda >= 0) && (n_lambda_terms == 1 )) { /* compatibility output */ sprintf(&(buf[bufplace]), "%s = %.4f", lambda, fep->init_lambda); } else { print_lambda_vector(fep, fep->init_fep_state, TRUE, FALSE, lambda_vec_str); print_lambda_vector(fep, fep->init_fep_state, TRUE, TRUE, lambda_name_str); sprintf(&(buf[bufplace]), "%s %d: %s = %s", lambdastate, fep->init_fep_state, lambda_name_str, lambda_vec_str); } } xvgr_subtitle(fp, buf, oenv); nsets_dhdl = 0; if (fep->dhdl_derivatives == edhdlderivativesYES) { nsets_dhdl = n_lambda_terms; } /* count the number of delta_g states */ nsets_de = fep->lambda_stop_n - fep->lambda_start_n; nsets = nsets_dhdl + nsets_de; /* dhdl + fep differences */ if (fep->n_lambda > 0 && (expand->elmcmove > elmcmoveNO)) { nsets += 1; /*add fep state for expanded ensemble */ } if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO) { nsets += 1; /* add energy to the dhdl as well */ } nsetsextend = nsets; if ((ir->epc != epcNO) && (fep->n_lambda > 0) && (fep->init_lambda < 0)) { nsetsextend += 1; /* for PV term, other terms possible if required for the reduced potential (only needed with foreign lambda, and only output when init_lambda is not set in order to maintain compatibility of the dhdl.xvg file) */ write_pV = TRUE; } snew(setname, nsetsextend); if (expand->elmcmove > elmcmoveNO) { /* state for the fep_vals, if we have alchemical sampling */ sprintf(buf, "%s", "Thermodynamic state"); setname[s] = gmx_strdup(buf); s += 1; } if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO) { switch (fep->edHdLPrintEnergy) { case edHdLPrintEnergyPOTENTIAL: sprintf(buf, "%s (%s)", "Potential Energy", unit_energy); break; case edHdLPrintEnergyTOTAL: case edHdLPrintEnergyYES: default: sprintf(buf, "%s (%s)", "Total Energy", unit_energy); } setname[s] = gmx_strdup(buf); s += 1; } if (fep->dhdl_derivatives == edhdlderivativesYES) { for (i = 0; i < efptNR; i++) { if (fep->separate_dvdl[i]) { if ( (fep->init_lambda >= 0) && (n_lambda_terms == 1 )) { /* compatibility output */ sprintf(buf, "%s %s %.4f", dhdl, lambda, fep->init_lambda); } else { double lam = fep->init_lambda; if (fep->init_lambda < 0) { lam = fep->all_lambda[i][fep->init_fep_state]; } sprintf(buf, "%s %s = %.4f", dhdl, efpt_singular_names[i], lam); } setname[s] = gmx_strdup(buf); s += 1; } } } if (fep->n_lambda > 0) { /* g_bar has to determine the lambda values used in this simulation * from this xvg legend. */ if (expand->elmcmove > elmcmoveNO) { nsetsbegin = 1; /* for including the expanded ensemble */ } else { nsetsbegin = 0; } if (fep->edHdLPrintEnergy != edHdLPrintEnergyNO) { nsetsbegin += 1; } nsetsbegin += nsets_dhdl; for (i = fep->lambda_start_n; i < fep->lambda_stop_n; i++) { print_lambda_vector(fep, i, FALSE, FALSE, lambda_vec_str); if ( (fep->init_lambda >= 0) && (n_lambda_terms == 1 )) { /* for compatible dhdl.xvg files */ nps = sprintf(buf, "%s %s %s", deltag, lambda, lambda_vec_str); } else { nps = sprintf(buf, "%s %s to %s", deltag, lambda, lambda_vec_str); } if (ir->bSimTemp) { /* print the temperature for this state if doing simulated annealing */ sprintf(&buf[nps], "T = %g (%s)", ir->simtempvals->temperatures[s-(nsetsbegin)], unit_temp_K); } setname[s] = gmx_strdup(buf); s++; } if (write_pV) { sprintf(buf, "pV (%s)", unit_energy); setname[nsetsextend-1] = gmx_strdup(buf); /* the first entry after nsets */ } xvgr_legend(fp, nsetsextend, (const char **)setname, oenv); for (s = 0; s < nsetsextend; s++) { sfree(setname[s]); } sfree(setname); } return fp; }
void linear_transform_loops (struct loops *loops) { unsigned int i; compute_immediate_uses (TDFA_USE_OPS | TDFA_USE_VOPS, NULL); for (i = 1; i < loops->num; i++) { unsigned int depth = 0; varray_type datarefs; varray_type dependence_relations; struct loop *loop_nest = loops->parray[i]; struct loop *temp; VEC (tree) *oldivs = NULL; VEC (tree) *invariants = NULL; lambda_loopnest before, after; lambda_trans_matrix trans; bool problem = false; bool need_perfect_nest = false; /* If it's not a loop nest, we don't want it. We also don't handle sibling loops properly, which are loops of the following form: for (i = 0; i < 50; i++) { for (j = 0; j < 50; j++) { ... } for (j = 0; j < 50; j++) { ... } } */ if (!loop_nest->inner) continue; depth = 1; for (temp = loop_nest->inner; temp; temp = temp->inner) { flow_loop_scan (temp, LOOP_ALL); /* If we have a sibling loop or multiple exit edges, jump ship. */ if (temp->next || temp->num_exits != 1) { problem = true; break; } depth ++; } if (problem) continue; /* Analyze data references and dependence relations using scev. */ VARRAY_GENERIC_PTR_INIT (datarefs, 10, "datarefs"); VARRAY_GENERIC_PTR_INIT (dependence_relations, 10, "dependence_relations"); compute_data_dependences_for_loop (depth, loop_nest, &datarefs, &dependence_relations); if (dump_file && (dump_flags & TDF_DETAILS)) { unsigned int j; for (j = 0; j < VARRAY_ACTIVE_SIZE (dependence_relations); j++) { struct data_dependence_relation *ddr = (struct data_dependence_relation *) VARRAY_GENERIC_PTR (dependence_relations, j); if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) { fprintf (dump_file, "DISTANCE_V ("); print_lambda_vector (dump_file, DDR_DIST_VECT (ddr), DDR_SIZE_VECT (ddr)); fprintf (dump_file, ")\n"); fprintf (dump_file, "DIRECTION_V ("); print_lambda_vector (dump_file, DDR_DIR_VECT (ddr), DDR_SIZE_VECT (ddr)); fprintf (dump_file, ")\n"); } } fprintf (dump_file, "\n\n"); } /* Build the transformation matrix. */ trans = lambda_trans_matrix_new (depth, depth); lambda_matrix_id (LTM_MATRIX (trans), depth); trans = try_interchange_loops (trans, depth, dependence_relations, datarefs, loop_nest); if (lambda_trans_matrix_id_p (trans)) { if (dump_file) fprintf (dump_file, "Won't transform loop. Optimal transform is the identity transform\n"); continue; } /* Check whether the transformation is legal. */ if (!lambda_transform_legal_p (trans, depth, dependence_relations)) { if (dump_file) fprintf (dump_file, "Can't transform loop, transform is illegal:\n"); continue; } if (!perfect_nest_p (loop_nest)) need_perfect_nest = true; before = gcc_loopnest_to_lambda_loopnest (loops, loop_nest, &oldivs, &invariants, need_perfect_nest); if (!before) continue; if (dump_file) { fprintf (dump_file, "Before:\n"); print_lambda_loopnest (dump_file, before, 'i'); } after = lambda_loopnest_transform (before, trans); if (dump_file) { fprintf (dump_file, "After:\n"); print_lambda_loopnest (dump_file, after, 'u'); } lambda_loopnest_to_gcc_loopnest (loop_nest, oldivs, invariants, after, trans); if (dump_file) fprintf (dump_file, "Successfully transformed loop.\n"); oldivs = NULL; invariants = NULL; free_dependence_relations (dependence_relations); free_data_refs (datarefs); } free_df (); scev_reset (); rewrite_into_loop_closed_ssa (); #ifdef ENABLE_CHECKING verify_loop_closed_ssa (); #endif }