Esempio n. 1
0
int main(){
  struct Variable var;
  
  var_init(&var, "lol", "lolllvm", V_INT);
  assert (strcmp("lol", var_get_name(&var)) == 0);
  assert (strcmp("lolllvm", var_get_llvm_name(&var)) == 0);
  assert (var_is_int(&var) != 0);
  assert (var_is_float(&var) == 0);
  assert (var_get_type(&var) == V_INT);
  assert (var_is_special(&var) == 0);


  var_init(&var, "lol", "lolllvm", V_FLOAT|V_SPECIAL);
  var_info(&var);
  assert (var_is_int(&var) == 0);
  assert (var_is_float(&var) != 0);
  assert (var_get_type(&var) == V_FLOAT);
  assert (var_is_special(&var) != 0);
  
  var_set_value(&var, -131);
  assert (var_get_value(&var) == -131);

  var_set_value(&var, 1.234);
  assert (((var_get_value(&var)) - 1.234) < 0.00001);
  assert (var_get_value(&var) != 1);
      
  var_set_modified(&var, V_MODIFIED);
  assert (var_is_modified(&var) != 0);
  var_set_modified(&var, V_NULL);
  assert (var_is_modified(&var) == 0);

  
  var_set_type(&var, V_FLOAT);
  assert (var_is_int(&var) == 0);
  assert (var_is_float(&var) != 0);
  assert (var_get_type(&var) == V_FLOAT);

  var_set_special(&var, V_SPECIAL);
  assert (var_is_special(&var) != 0);


  var_set_type(&var, V_INT);
  assert (var_is_int(&var) != 0);
  assert (var_is_float(&var) == 0);
  assert (var_get_type(&var) == V_INT);

  var_set_access(&var, V_NULL);
  assert (var_is_writable(&var) == 0);
  var_set_access(&var, V_WRITABLE);
  assert (var_is_writable(&var) != 0);

  var.flags |= 1;
  assert (var_is_declared(&var) != 0);

  /* var_set_nb_args(&var, 13); */
  /* assert (var_get_nb_args(&var) == 13); */

  printf("Tests OK (sauf get_nb_args)\n");
}  
Esempio n. 2
0
/** 
 * \ingroup vars
 * \brief   Set the name and value of a variable
 *  
 * Set variable \p var to \p name and \p value.
 *
 * \param var   variable object
 * \param name  string name (null-terminated)
 * \param value string value (null-terminated)
 *  
 * \return \c 0 if successful, non-zero on error
 */ 
int var_set(var_t *var, const char *name, const char *value)
{
    dbg_err_if (var == NULL);
    dbg_err_if (name == NULL);
    dbg_err_if (value == NULL);
    
    dbg_err_if(var_set_name(var, name));
    dbg_err_if(var_set_value(var, value));

    return 0;
err:
    return ~0;
}
Esempio n. 3
0
File: var.c Progetto: aharri/base
static void
set_magic_shell_variable()
{
	const char *name = "SHELL";
	const char *ename = NULL;
	uint32_t k;
	Var *v;

	k = ohash_interval(name, &ename);
	v = find_global_var_without_env(name, ename, k);
	var_set_value(v, _PATH_BSHELL);
	/* XXX the environment shall never affect it */
	v->flags = VAR_SHELL | VAR_SEEN_ENV;
}
Esempio n. 4
0
File: var.c Progetto: aharri/base
/* Helper for find_global_var(): grab environment value if needed.
 */
static void
fill_from_env(Var *v)
{
	char	*env;

	env = getenv(v->name);
	if (env == NULL)
		v->flags |= VAR_SEEN_ENV;
	else {
		var_set_value(v, env);
		v->flags |= VAR_FROM_ENV | VAR_SEEN_ENV;
	}

#ifdef STATS_VAR_LOOKUP
	STAT_VAR_FROM_ENV++;
#endif
}
Esempio n. 5
0
//-------------------------------------------------------------------------
void Prg_ASCEND::update_fbd()
{
  int i, idx, row_idx;
  int m, me;
  int32 calc_ok;
  double residual, mult;

  // write current optimization variables to ASCEND
  for (i = 0; i < _nvars; i++) {
    idx = _var_asc2hqp[i];
    if (idx >= 0)
      var_set_value(_vars[i], _x[idx]);
  }

  // update variable bounds
  update_bounds();

  // update objective
  _f = relman_eval(_obj, &calc_ok, _safe_calc);
  _slv_status.calc_ok &= calc_ok;

  // update general constraints
  me = _me_bounds;
  m = _m_bounds;
  for (i = 0; i < _nrels; i++) {
    residual = relman_eval(_rels[i], &calc_ok, _safe_calc);
    _slv_status.calc_ok &= calc_ok;
    if (rel_equal(_rels[i])) {
      row_idx = me++;
      _qp->b[row_idx] = residual;
    }
    else {
      row_idx = m++;
      mult = rel_less(_rels[i])? -1.0: 1.0;
      _qp->d[row_idx] = mult * residual;
    }
  }
}
Esempio n. 6
0
File: var.c Progetto: aharri/base
void
Var_SubstVar(Buffer buf,	/* To store result */
    const char *str,		/* The string in which to substitute */
    struct LoopVar *l,		/* Handle */
    const char *val)		/* Its value */
{
	const char *var = l->me->name;

	var_set_value(l->me, val);

	for (;;) {
		const char *start;
		/* Copy uninteresting stuff */
		for (start = str; *str != '\0' && *str != '$'; str++)
			;
		Buf_Addi(buf, start, str);

		start = str;
		if (*str++ == '\0')
			break;
		str++;
		/* and escaped dollars */
		if (start[1] == '$') {
			Buf_Addi(buf, start, start+2);
			continue;
		}
		/* Simple variable, if it's not us, copy.  */
		if (start[1] != '(' && start[1] != '{') {
			if (start[1] != *var || var[1] != '\0') {
				Buf_AddChars(buf, 2, start);
				continue;
		    }
		} else {
			const char *p;
			char paren = start[1];


			/* Find the end of the variable specification.  */
			p = find_pos(paren)(str);
			/* A variable inside the variable. We don't know how to
			 * expand the external variable at this point, so we
			 * try  again with the nested variable.	*/
			if (*p == '$') {
				Buf_Addi(buf, start, p);
				str = p;
				continue;
			}

			if (strncmp(var, str, p - str) != 0 ||
				var[p - str] != '\0') {
				/* Not the variable we want to expand.	*/
				Buf_Addi(buf, start, p);
				str = p;
				continue;
			}
			if (*p == ':') {
				bool doFree;	/* should val be freed ? */
				char *newval;
				struct Name name;

				doFree = false;
				name.s = var;
				name.e = var + (p-str);

				/* val won't be freed since !doFree, but
				 * VarModifiers_Apply doesn't know that,
				 * hence the cast. */
				newval = VarModifiers_Apply((char *)val,
				    &name, NULL, false, &doFree, &p, paren);
				Buf_AddString(buf, newval);
				if (doFree)
					free(newval);
				str = p;
				continue;
			} else
				str = p+1;
		}
		Buf_AddString(buf, val);
	}
}
Esempio n. 7
0
static void ExecuteStatement(GNode* node, gpointer data)
{
	Statement* stmt = (Statement*) node->data;
	Verbose("* Visiting GNode at level %d", g_node_depth(node));

	if (parseOnly && (stmt->type < STMT_REPEAT)) return;

	switch (stmt->type) {
		case STMT_ASSIGN: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* varident = param_string_get(paramList, 0, &status[0]);
			Expression* expression = param_index_get(paramList, 1);

			// evaluator error check
			if (status[0] != STATUS_EVAL_OK) {
				Error("Malicious assign parameters! (status = %s)", expr_status_to_string(status[0]));
			}

			switch (expression->type) {
				case EXPR_RICH_INT:
				case EXPR_CONSTANT_INT: {
					Verbose("~ Executing STMT_ASSIGN: variable = %s, type = INT", varident);
					glong result = param_int_get(paramList, 1, &status[1]);

					// evaluator error check
					if (status[1] != STATUS_EVAL_OK) {
						Error("Malicious assign parameters! (status = %s)", expr_status_to_string(status[1]));
					}

					var_set_value(varident, VAR_INT, &result);
					break;
				}

				case EXPR_RICH_STRING:
				case EXPR_CONSTANT_STRING: {
					Verbose("~ Executing STMT_ASSIGN: variable = %s, type = STRING", varident);
					gchar* result_raw = param_string_get(paramList, 1, &status[1]);

					// evaluator error check
					if (status[1] != STATUS_EVAL_OK) {
						Error("Malicious assign parameters! (status = %s)", expr_status_to_string(status[1]));
					}

					gchar* result = var_replace_substrings(result_raw);

					var_set_value(varident, VAR_STRING, result);
					g_free(result_raw);
					g_free(result);
					break;
				}

				default: Error("Expression type %d not supported in assign statement!\n", expression->type);
			}

			g_free(varident);
			break;
		}

		case STMT_REPEAT: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* varident = param_string_get(paramList, 0, &status[0]);
			glong i, loopCount = param_int_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_REPEAT: variable = %s, loopCount = %ld", varident, loopCount);

			g_assert(loopCount >= 0);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious repeat parameters! (%s:%d)", __FILE__, __LINE__);
			}

			for (i=0; i<loopCount; i++) {
				var_set_value(varident, VAR_INT, &i);
				g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);
			}

			var_destroy(varident);
			g_free(varident);
			break;
		}

		case STMT_TIME: {
			Verbose("~ Executing STMT_TIME: label = %s", stmt->label);

			static gint timeId = 0;
			gdouble time;
			GTimer* timer = g_timer_new();

			g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);

			g_timer_stop(timer);
			time = g_timer_elapsed(timer, NULL);
			g_timer_destroy(timer);

			gchar* label = var_replace_substrings(stmt->label);
			timeList = g_slist_prepend(timeList, timeevent_new(timeId++, label, time));
			g_free(label);
			break;
		}

		case STMT_CTIME: {
			Verbose("~ Executing STMT_CTIME: label = %s", stmt->label);

			static gint coreTimeId = 0;
			gchar* label = var_replace_substrings(stmt->label);
			CoreTimeEvent* coreTimeEvent = coretime_event_new(coreTimeId++, label, coretime_new(0, 0));
			coreTimeStack = g_list_prepend(coreTimeStack, coreTimeEvent);

			g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);

			coreTimeList = g_slist_prepend(coreTimeList, coreTimeEvent);
			coreTimeStack = g_list_remove_link(coreTimeStack, g_list_first(coreTimeStack));
			g_free(label);
			break;
		}

#ifdef HAVE_MPI
		case STMT_GROUP: {
			Verbose("~ Executing STMT_GROUP: group = %s", stmt->label);

			GroupBlock* groupBlock = g_hash_table_lookup(groupMap, stmt->label);

			if(groupBlock && groupBlock->member) {
				groupStack = g_list_prepend(groupStack, groupBlock);
				g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);
				groupStack = g_list_remove_link(groupStack, g_list_first(groupStack));
			}
			else if(!groupBlock) {
				backtrace(stmt);
				Error("Group \"%s\" doesn't exist!", stmt->label);
			}
			break;
		}

		case STMT_MASTER: {
			GroupBlock* groupBlock;
			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack) {
				groupBlock = (GroupBlock*) g_list_first(groupStack)->data;
				comm = groupBlock->mpicomm;
			}

			gint groupRank;
			MPI_ASSERT(MPI_Comm_rank(comm, &groupRank), "Master Statement", TRUE)

			if(groupStack) Verbose("~ Executing STMT_MASTER: rank = %d, type = implicit group", groupRank);
			else           Verbose("~ Executing STMT_MASTER: rank = %d, type = world", groupRank);

			if(groupRank == MASTER) {
				g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);
			}
			else Verbose("Im not the master here... groupRank = %d", groupRank);
			break;
		}

		case STMT_BARRIER: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* groupName = param_string_get_optional(paramList, 0, &status[0], NULL);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			GroupBlock* groupBlock = groupblock_get(groupName);

			if(groupName)  Verbose("~ Executing STMT_BARRIER: type = explicit group, name = %s", groupName);
			else           Verbose("~ Executing STMT_BARRIER: type = implicit active group");

			MPI_ASSERT(MPI_Barrier(groupBlock->mpicomm), "Barrier Statement", TRUE)

			g_free(groupName);
			break;
		}
#endif

		case STMT_SLEEP: {
			if (agileMode) return;
			Verbose("~ Executing STMT_SLEEP");

			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			glong time = param_int_get(paramList, 0, &status[0]);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			g_usleep(time);
			//sleep(time);
			break;
		}

		case STMT_BLOCK: {
			Verbose("~ Executing STMT_BLOCK");
			g_node_children_foreach(node, G_TRAVERSE_ALL, &ExecuteStatement, NULL);
			break;
		}

		case STMT_PRINT: {
			Verbose("~ Executing STMT_PRINT");

			ParameterList* paramList = stmt->parameters;
			GString* buffer = g_string_new("");
			ExpressionStatus status;
			gint i;

			for (i=0; i<paramList->len; i++) {
				gchar* string = param_string_get(paramList, i, &status);
				if (status == STATUS_EVAL_OK) {
					g_string_append(buffer, string);
					g_free(string);
					if (i < (paramList->len-1))
						g_string_append(buffer, " ");
				}
				else {
					backtrace(stmt);
					Error("Error during print parameter evaluation (index=%d, status=%s).\n",
							i, expr_status_to_string(status));
				}
			}

			gchar* processed = var_replace_substrings(buffer->str);
			g_printf("[%d] %s\n", rank, processed);
			g_free(processed);
			g_string_free(buffer, TRUE);
			break;
		}

		case STMT_FCREAT: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* fhname = param_string_get(paramList, 0, &status[0]);
			gchar* fname_raw = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_FCREAT: fhname = %s, fname = %s", fhname, fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			File* file;
			IOStatus ioStatus = iio_fcreat(fname, &file);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success) {
				Verbose("  > file = %p", file);
				var_set_value(fhname, VAR_FILE, &file);
				statementsSucceed[STMT_FCREAT]++;
			}
			else
				statementsFail[STMT_FCREAT]++;

			g_free(fhname);
			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_FOPEN: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			gchar* fhname = param_string_get(paramList, 0, &status[0]);
			gchar* fname_raw = param_string_get(paramList, 1, &status[1]);
			gint   flags = param_int_get(paramList, 2, &status[2]);

			Verbose("~ Executing STMT_FOPEN: fhname = %s, fname = %s, flags = %d", fhname, fname_raw, flags);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			File* file;
			IOStatus ioStatus = iio_fopen(fname, flags, &file);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success) {
				Verbose("  > file = %p", file);
				var_set_value(fhname, VAR_FILE, &file);
				statementsSucceed[STMT_FOPEN]++;
			}
			else
				statementsFail[STMT_FOPEN]++;

			g_free(fhname);
			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_FCLOSE: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_FCLOSE: file = %p", file);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			g_assert(file);

			IOStatus ioStatus = iio_fclose(file);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success) {
				gchar* fhname = (gchar*) param_value_get(paramList, 0);
				var_destroy(fhname);
				statementsSucceed[STMT_FCLOSE]++;
			}
			else
				statementsFail[STMT_FCLOSE]++;
			break;
		}

		case STMT_FREAD: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);
			glong dataSize = param_int_get_optional(paramList, 1, &status[1], READALL);
			glong offset = param_int_get_optional(paramList, 2, &status[2], OFFSET_CUR);

			Verbose("~ Executing STMT_FREAD: file = %p, dataSize = %ld, offset = %ld", file, dataSize, offset);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			IOStatus ioStatus = iio_fread(file, dataSize, offset);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_FREAD]++;
			else
				statementsFail[STMT_FREAD]++;
			break;
		}

		case STMT_FWRITE: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);
			glong dataSize = param_int_get(paramList, 1, &status[1]);
			glong offset = param_int_get_optional(paramList, 2, &status[2], -1);

			Verbose("~ Executing STMT_FWRITE: file = %p, dataSize = %ld, offset = %ld", file, dataSize, offset);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			IOStatus ioStatus = iio_fwrite(file, dataSize, offset);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_FWRITE]++;
			else
				statementsFail[STMT_FWRITE]++;
			break;
		}

		case STMT_FSEEK: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);
			glong offset = param_int_get(paramList, 1, &status[1]);
			gint whence = param_int_get_optional(paramList, 2, &status[2], SEEK_SET);

			Verbose("~ Executing STMT_FSEEK: file = %p, offset = %ld, whence = %d", file, offset, whence);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			IOStatus ioStatus = iio_fseek(file, offset, whence);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_FSEEK]++;
			else
				statementsFail[STMT_FSEEK]++;
			break;
		}

		case STMT_FSYNC: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			IOStatus ioStatus = iio_fsync(file);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_FSYNC]++;
			else {
				statementsFail[STMT_FSYNC]++;
			}
			break;
		}

		case STMT_WRITE: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);
			glong  dataSize = param_int_get(paramList, 1, &status[1]);
			glong  offset = param_int_get_optional(paramList, 2, &status[2], 0);

			Verbose("~ Executing STMT_WRITE: file = %s, dataSize = %ld, offset = %ld", fname_raw, dataSize, offset);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_write(fname, dataSize, offset);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_WRITE]++;
			else
				statementsFail[STMT_WRITE]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_APPEND: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);
			glong  dataSize = param_int_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_APPEND: file = %s, dataSize = %ld", fname_raw, dataSize);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_append(fname, dataSize);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_APPEND]++;
			else
				statementsFail[STMT_APPEND]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_READ: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);
			glong  dataSize = param_int_get_optional(paramList, 1, &status[1], READALL);
			glong  offset = param_int_get_optional(paramList, 2, &status[2], 0);

			Verbose("~ Executing STMT_READ: file = %s, dataSize = %ld, offset = %ld",
					fname_raw, dataSize, offset);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_read(fname, dataSize, offset);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_READ]++;
			else
				statementsFail[STMT_READ]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_LOOKUP: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_LOOKUP: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_lookup(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_LOOKUP]++;
			else
				statementsFail[STMT_LOOKUP]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_DELETE: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_DELETE: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_delete(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_DELETE]++;
			else
				statementsFail[STMT_DELETE]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_MKDIR: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_MKDIR: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_mkdir(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_MKDIR]++;
			else
				statementsFail[STMT_MKDIR]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_RMDIR: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_RMDIR: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_rmdir(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_RMDIR]++;
			else
				statementsFail[STMT_RMDIR]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_CREATE: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_CREATE: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_create(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_CREATE]++;
			else
				statementsFail[STMT_CREATE]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_STAT: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_STAT: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			IOStatus ioStatus = iio_stat(fname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_STAT]++;
			else
				statementsFail[STMT_STAT]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}

		case STMT_RENAME: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* oldname_raw = param_string_get(paramList, 0, &status[0]);
			gchar* newname_raw = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_RENAME: oldname = %s, newname = %s", oldname_raw, oldname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* oldname = var_replace_substrings(oldname_raw);
			gchar* newname = var_replace_substrings(newname_raw);

			IOStatus ioStatus = iio_rename(oldname, newname);
			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_RENAME]++;
			else
				statementsFail[STMT_RENAME]++;

			g_free(oldname_raw);
			g_free(newname_raw);
			g_free(oldname);
			g_free(newname);
			break;
		}

#ifdef HAVE_MPI
		case STMT_PFOPEN: {
			ExpressionStatus status[3];
			ParameterList* paramList = stmt->parameters;
			gchar* fhname = param_string_get(paramList, 0, &status[0]);
			gchar* fname_raw = param_string_get(paramList, 1, &status[1]);
			gchar* mode = param_string_get(paramList, 2, &status[2]);

			Verbose("~ Executing STMT_FOPEN: fhname = %s, fname = %s mode = %s", fhname, fname_raw, mode);

			// evaluator error check
			if (!expr_status_assert(status, 3)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);
			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack)
				comm = ((GroupBlock*) g_list_first(groupStack)->data)->mpicomm;

			File* file;
			if (iio_pfopen(fname, mode, comm, &file)) {
				Verbose("  > file = %p", file);
				var_set_value(fhname, VAR_FILE, &file);
				statementsSucceed[STMT_PFOPEN]++;
			}
			else
				statementsFail[STMT_PFOPEN]++;

			g_free(fhname);
			g_free(fname_raw);
			g_free(fname);
			g_free(mode);
			break;
		}

		case STMT_PFCLOSE: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			File* file = param_file_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_FCLOSE: file = %p", file);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			if (file && iio_pfclose(file)) {
				gchar* fhname = (gchar*) param_value_get(paramList, 0);
				var_destroy(fhname);
				statementsSucceed[STMT_PFCLOSE]++;
			}
			else
				statementsFail[STMT_PFCLOSE]++;
			break;
		}

		case STMT_PFWRITE: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			File*  file = param_file_get(paramList, 0, &status[0]);
			gchar* pname = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_PFWRITE: file = %p, pattern = %s", file, pname);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			Pattern* pattern = g_hash_table_lookup(patternMap, pname);
			if (!pattern) {
				g_printf("Invalid pattern parameter in statement pfwrite.\n");
				Error("Malicious statement parameters!");
				break;
			}

			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack)
				comm = ((GroupBlock*) g_list_first(groupStack)->data)->mpicomm;

			IOStatus ioStatus;
			switch(pattern->level) {
				/* Level 0: non-collective, contiguous */
				case 0:
					Verbose("  > level = 0");
					ioStatus = iio_pfwrite_level0(file, pattern);
					break;

				/* Level 1: collective, contiguous */
				case 1:
					Verbose("  > level = 1");
					ioStatus = iio_pfwrite_level1(file, pattern);
					break;

				/* Level 2: non-collective, non-contiguous */
				case 2:
					Verbose("  > level = 2");
					ioStatus = iio_pfwrite_level2(file, pattern);
					break;

				/* Level 3: collective, non-contiguous */
				case 3:
					Verbose("  > level = 3");
					ioStatus = iio_pfwrite_level3(file, pattern);
					break;

				default: Error("Invalid level (%d) for statement pfwrite!", pattern->level);
			}

			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_PFWRITE]++;
			else
				statementsFail[STMT_PFWRITE]++;

			g_free(pname);
			break;
		}

		case STMT_PFREAD: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			File*  file = param_file_get(paramList, 0, &status[0]);
			gchar* pname = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_PFREAD: file = %p, pattern = %s", file, pname);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			Pattern* pattern = g_hash_table_lookup(patternMap, pname);
			if (!pattern) {
				g_printf("Invalid pattern parameter in statement pread.\n");
				Error("Malicious statement parameters!");
				break;
			}

			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack)
				comm = ((GroupBlock*) g_list_first(groupStack)->data)->mpicomm;

			IOStatus ioStatus;
			switch(pattern->level) {
				/* Level 0: non-collective, contiguous */
				case 0:
					Verbose("  > level = 0");
					ioStatus = iio_pfread_level0(file, pattern);
					break;

				/* Level 1: collective, contiguous */
				case 1:
					Verbose("  > level = 1");
					ioStatus = iio_pfread_level1(file, pattern);
					break;

				/* Level 2: non-collective, non-contiguous */
				case 2:
					Verbose("  > level = 2");
					ioStatus = iio_pfread_level2(file, pattern);
					break;

				/* Level 3: collective, non-contiguous */
				case 3:
					Verbose("  > level = 3");
					ioStatus = iio_pfread_level3(file, pattern);
					break;

				default: Error("Invalid level (%d) for statement pfread!", pattern->level);
			}

			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_PFREAD]++;
			else
				statementsFail[STMT_PFREAD]++;

			g_free(pname);
			break;
		}

		case STMT_PWRITE: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);
			gchar* pname = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_PWRITE: file = %s, pattern = %s", fname_raw, pname);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			Pattern* pattern = g_hash_table_lookup(patternMap, pname);
			if (!pattern) {
				g_printf("Invalid pattern parameter in statement pwrite.\n");
				Error("Malicious statement parameters!");
				break;
			}

			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack)
				comm = ((GroupBlock*) g_list_first(groupStack)->data)->mpicomm;

			IOStatus ioStatus;
			switch(pattern->level) {
				/* Level 0: non-collective, contiguous */
				case 0:
					Verbose("  > level = 0");
					ioStatus = iio_pwrite_level0(fname, pattern, comm);
					break;

				/* Level 1: collective, contiguous */
				case 1:
					Verbose("  > level = 1");
					ioStatus = iio_pwrite_level1(fname, pattern, comm);
					break;

				/* Level 2: non-collective, non-contiguous */
				case 2:
					Verbose("  > level = 2");
					ioStatus = iio_pwrite_level2(fname, pattern, comm);
					break;

				/* Level 3: collective, non-contiguous */
				case 3:
					Verbose("  > level = 3");
					ioStatus = iio_pwrite_level3(fname, pattern, comm);
					break;

				default: Error("Invalid level (%d) for statement pwrite!", pattern->level);
			}

			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_PWRITE]++;
			else
				statementsFail[STMT_PWRITE]++;

			g_free(fname_raw);
			g_free(fname);
			g_free(pname);
			break;
		}

		case STMT_PREAD: {
			ExpressionStatus status[2];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);
			gchar* pname = param_string_get(paramList, 1, &status[1]);

			Verbose("~ Executing STMT_PREAD: file = %s, pattern = %s", fname_raw, pname);

			// evaluator error check
			if (!expr_status_assert(status, 2)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			Pattern* pattern = g_hash_table_lookup(patternMap, pname);
			if (!pattern) {
				g_printf("Invalid pattern parameter in statement pread.\n");
				g_free(fname);
				Error("Malicious statement parameters!");
				break;
			}

			MPI_Comm comm = MPI_COMM_WORLD;
			if(groupStack)
				comm = ((GroupBlock*) g_list_first(groupStack)->data)->mpicomm;

			IOStatus ioStatus;
			switch(pattern->level) {
				/* Level 0: non-collective, contiguous */
				case 0:
					Verbose("  > level = 0");
					ioStatus = iio_pread_level0(fname, pattern, comm);
					break;

				/* Level 1: collective, contiguous */
				case 1:
					Verbose("  > level = 1");
					ioStatus = iio_pread_level1(fname, pattern, comm);
					break;

				/* Level 2: non-collective, non-contiguous */
				case 2:
					Verbose("  > level = 2");
					ioStatus = iio_pread_level2(fname, pattern, comm);
					break;

				/* Level 3: collective, non-contiguous */
				case 3:
					Verbose("  > level = 3");
					ioStatus = iio_pread_level3(fname, pattern, comm);
					break;

				default: Error("Invalid level (%d) for statement pread!", pattern->level);
			}

			dump_coretime(coreTimeStack, ioStatus.coreTime);

			if (ioStatus.success)
				statementsSucceed[STMT_PREAD]++;
			else
				statementsFail[STMT_PREAD]++;

			g_free(fname_raw);
			g_free(fname);
			g_free(pname);
			break;
		}

		case STMT_PDELETE: {
			ExpressionStatus status[1];
			ParameterList* paramList = stmt->parameters;
			gchar* fname_raw = param_string_get(paramList, 0, &status[0]);

			Verbose("~ Executing STMT_PDELETE: file = %s", fname_raw);

			// evaluator error check
			if (!expr_status_assert(status, 1)) {
				backtrace(stmt);
				Error("Malicious statement parameters!");
			}

			gchar* fname = var_replace_substrings(fname_raw);

			if (iio_pdelete(fname))
				statementsSucceed[STMT_PDELETE]++;
			else
				statementsFail[STMT_PDELETE]++;

			g_free(fname_raw);
			g_free(fname);
			break;
		}
#endif

		/* ![ModuleHook] statement_exec */

		default: Error("Invalid statement! (id=%d)\n", stmt->type);
	}
}
Esempio n. 8
0
void iiSetParameters(int argc, char ** argv)
{
	// load default arguments into variables.
	{
		GSList* cur = paramList;

		while(cur != NULL){

			param_list_entry * param_entry = (param_list_entry*) cur->data;
			env_list_entry * env_entry = (env_list_entry*) malloc(sizeof(env_list_entry));

			env_entry->env_name = malloc(2048*sizeof(gchar));
			//env_entry->env_value = malloc(2048*sizeof(gchar));

			// Override default, with value of environment variable
			g_snprintf(env_entry->env_name, 2048, "PARABENCH_%s", param_entry->param_name);
			//sprintf(env_entry->env_name, "PARABENCH_%s", param_entry->param_name);
			env_entry->env_value = getenv(env_entry->env_name);
			

			// now set the values:
			// use environment as default if set
			if ( env_entry->env_value != NULL )
			{
				var_set_value(param_entry->var_name, VAR_STRING, env_entry->env_value);
				printf("Parameter: %s, %s=%s\n", param_entry->var_name, env_entry->env_name, env_entry->env_value );
			} else {
				var_set_value(param_entry->var_name, VAR_STRING, param_entry->default_value);
			}

			free(env_entry->env_name);
			free(env_entry);

			cur = cur->next;
		}
	}

	gint i;
	for (i=0; i < argc; i++){	 	  
		char * value=strstr(argv[i], "=");
		if(value == NULL){
			printf("Error, specify parameters with <PARAM>=<VALUE>\n");
			exit(1);
		}
		value[0] = 0;
		value++;
		char * param=argv[i];

		//printf("Setting: %s to %s\n", param, value);

		// check if paramList contains variable:
		GSList * cur = paramList;
		while(cur != NULL){

			param_list_entry * param_entry = (param_list_entry*) cur->data;

			if(strcmp(param_entry->param_name, param) == 0){
				// now set the values:
				//printf("Setting: %s to %s\n", param_entry->var_name, value);
				var_set_value(param_entry->var_name, VAR_STRING, value);
				break;
			}


			cur = cur->next;
		}

		if(cur == NULL){
			printf("Error, unknown parameter %s with value \"%s\"\n", param, value);
			exit(1);
		}
	}
}
Esempio n. 9
0
//-------------------------------------------------------------------------
void Prg_ASCEND::update(const VECP y, const VECP z)
{
  var_filter_t vfilter;
  int i, j, row_idx, idx;
  int m, me;
  int32 count;
  int status, newel;
  real64 residual;
  double mult;
  SPMAT *J;

  // write current optimization variables to ASCEND
  for (j = 0; j < _nvars; j++) {
    idx = _var_asc2hqp[j];
    if (idx >= 0)
      var_set_value(_vars[j], _x[idx]);
  }

  // update variable bounds
  update_bounds();

  // initialize vfilter so that all optimization variables are considered
  vfilter.matchbits = (VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR | VAR_FIXED);
  vfilter.matchvalue = (VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR);

  // update objective and derivatives
  status = relman_diff_grad(_obj, &vfilter, _derivatives->ve,
			    _var_master_idxs->ive, _var_solver_idxs->ive,
			    &count, &residual, _safe_calc);
  if (status == 0) // todo: this contradicts docu in solver/relman.h!?
    _slv_status.calc_ok &= FALSE;
  _f = residual;
  for (j = 0; j < count; j++) {
    idx = _var_asc2hqp[_var_solver_idxs[j]];
    if (idx >= 0)
      _qp->c[idx] = _derivatives[j];
  }

  // update general constraints
  me = _me_bounds;
  m = _m_bounds;
  newel = 0;
  for (i = 0; i < _nrels; i++) {
    status = relman_diff_grad(_rels[i], &vfilter, _derivatives->ve,
			      _var_master_idxs->ive, _var_solver_idxs->ive,
			      &count, &residual, _safe_calc);
    if (status == 0) // todo: this contradicts docu in solver/relman.h!?
      _slv_status.calc_ok &= FALSE;
    if (rel_equal(_rels[i])) {
      row_idx = me++;
      mult = 1.0;
      _qp->b[row_idx] = residual;
      J = _qp->A;
    }
    else {
      row_idx = m++;
      mult = rel_less(_rels[i])? -1.0: 1.0;
      _qp->d[row_idx] = mult * residual;
      J = _qp->C;
    }
    sprow_zero(J->row + row_idx);
    for (j = 0; j < count; j++) {
      idx = _var_asc2hqp[_var_solver_idxs[j]];
      if (idx >= 0)
	newel |= sp_update_val(J, row_idx, idx, mult * _derivatives[j]);
    }      
  }
  if (newel) {
    // the sparsity structure has changed
    _slv_status.ok = FALSE;
    _slv_status.inconsistent = TRUE;
    _slv_status.ready_to_solve = FALSE;
  }
}