struct lexer *lexer_create_substitution(struct lexer *lx, struct token *t) { char *substitution = NULL; if(lx->environment) { substitution = dag_variable_lookup_string(t->lexeme, lx->environment); } struct lexer *lx_s; if(!substitution) { fatal("Variable %s has not yet been defined at line % " PRId64 ".\n", t->lexeme, lx->line_number); substitution = xxstrdup(""); } lx_s = lexer_create(STRING, substitution, lx->line_number, lx->column_number); lx_s->depth = lx->depth + 1; if(lx_s->depth > MAX_SUBSTITUTION_DEPTH) lexer_report_error(lx, "More than %d recursive subsitutions attempted.\n", MAX_SUBSTITUTION_DEPTH); free(substitution); return lx_s; }
static int dag_parse_node_command(struct lexer *bk, struct dag_node *n) { struct token *t; //Jump COMMAND token. t = lexer_next_token(bk); lexer_free_token(t); char *local = dag_variable_lookup_string("BATCH_LOCAL", bk->environment); if(local) { if(string_istrue(local)) n->local_job = 1; free(local); } /* Read command modifiers. */ while((t = lexer_peek_next_token(bk)) && t->type != TOKEN_COMMAND_MOD_END) { t = lexer_next_token(bk); if(strcmp(t->lexeme, "LOCAL") == 0) { n->local_job = 1; } else if(strcmp(t->lexeme, "MAKEFLOW") == 0) { n->nested_job = 1; } else { lexer_report_error(bk, "Parser does not know about modifier: %s.\n", t->lexeme); } lexer_free_token(t); } if(!t) { lexer_report_error(bk, "Malformed command."); } //Free COMMAND_MOD_END token. t = lexer_next_token(bk); lexer_free_token(t); if(n->nested_job) { return dag_parse_node_nested_makeflow(bk, n); } else { return dag_parse_node_regular_command(bk, n); } }
struct jx * dag_node_env_create( struct dag *d, struct dag_node *n ) { struct dag_variable_lookup_set s = { d, n->category, n, NULL }; char *key; struct jx *object = jx_object(0); char *num_cores = dag_variable_lookup_string(RESOURCES_CORES, &s); char *num_omp_threads = dag_variable_lookup_string("OMP_NUM_THREADS", &s); if (num_cores && !num_omp_threads) { // if number of cores is set, number of omp threads is not set, // then we set number of omp threads to number of cores jx_insert(object, jx_string("OMP_NUM_THREADS"), jx_string(num_cores)); } else if (num_omp_threads) { // if number of omp threads is set, then we set number of cores // to the number of omp threads jx_insert(object, jx_string(RESOURCES_CORES), jx_string(num_omp_threads)); } else { // if both number of cores and omp threads are not set, we // set them to 1 jx_insert(object, jx_string("OMP_NUM_THREADS"), jx_string("1")); jx_insert(object, jx_string(RESOURCES_CORES), jx_string("1")); } set_first_element(d->export_vars); while((key = set_next_element(d->export_vars))) { char *value = dag_variable_lookup_string(key, &s); if(value) { jx_insert(object,jx_string(key),jx_string(value)); debug(D_MAKEFLOW_RUN, "export %s=%s", key, value); } } free(num_cores); free(num_omp_threads); return object; }
void dag_node_fill_resources(struct dag_node *n) { struct rmsummary *rs = n->resources; struct dag_variable_lookup_set s = { n->d, n->category, n, NULL }; char *val_str; val_str = dag_variable_lookup_string(RESOURCES_CORES, &s); if(val_str) rs->cores = atoll(val_str); val_str = dag_variable_lookup_string(RESOURCES_DISK, &s); if(val_str) rs->workdir_footprint = atoll(val_str); val_str = dag_variable_lookup_string(RESOURCES_MEMORY, &s); if(val_str) rs->resident_memory = atoll(val_str); val_str = dag_variable_lookup_string(RESOURCES_GPUS, &s); if(val_str) rs->gpus = atoll(val_str); }
struct nvpair * dag_node_env_create( struct dag *d, struct dag_node *n ) { struct dag_variable_lookup_set s = { d, n->category, n, NULL }; char *key; struct nvpair *nv = 0; set_first_element(d->export_vars); while((key = set_next_element(d->export_vars))) { char *value = dag_variable_lookup_string(key, &s); if(value) { if(!nv) nv = nvpair_create(); nvpair_insert_string(nv,key,value); debug(D_MAKEFLOW_RUN, "export %s=%s", key, value); } } return nv; }
struct token *lexer_concat_expandable(struct lexer *lx, struct list *tokens) { struct token *t; struct buffer b; buffer_init(&b); char *substitution; list_first_item(tokens); while((t = list_pop_head(tokens))) { switch(t->type) { case TOKEN_SUBSTITUTION: substitution = dag_variable_lookup_string(t->lexeme, lx->environment); if(!substitution) fatal("Variable %s has not yet been defined at line % " PRId64 ".\n", t->lexeme, lx->line_number); buffer_printf(&b, "%s", substitution); free(substitution); break; case TOKEN_LITERAL: if(strcmp(t->lexeme, "") != 0) // Skip empty strings. buffer_printf(&b, "%s", t->lexeme); break; default: lexer_report_error(lx, "Error in expansion, got: %s.\n", lexer_print_token(t)); break; } lexer_free_token(t); } t = lexer_pack_token(lx, TOKEN_LITERAL); t->lexeme = xxstrdup(buffer_tostring(&b)); buffer_free(&b); return t; }
char *dag_variable_lookup_global_string(const char *name, struct dag *d ) { struct dag_variable_lookup_set s = { d, NULL, NULL, NULL }; return dag_variable_lookup_string(name, &s); }