Пример #1
0
void Tte_Swaps::init_tab_sheduled()
{
	this->tab=new double*[this->objects_needed.assumptions->model_period];
	for(int i=0;i<this->objects_needed.assumptions->model_period;++i)
	{
		this->tab[i]=new double[this->objects_needed.assumptions->model_period];
	}
	ofstream debug_file("DEBUGGG.txt");
	double maturity=0;
	for(int j=0;j<this->objects_needed.assumptions->model_period;++j)
	{
		if(j%this->objects_needed.assumptions->length_of_futures_contract==0)
		{
			maturity+=this->objects_needed.assumptions->length_of_futures_contract;
		}
		for(int i=0;i<this->objects_needed.assumptions->model_period;++i)
		{
			if (i<j||i>maturity)
				this->tab[i][j]=0;
			else 
			{
				debug_file<<"i="<<i<<",j="<<j<<endl;
				debug_file<<"	maturity="<<maturity<<endl;
				this->tab[i][j]=(double)(maturity
				-i)/this->objects_needed.assumptions->nb_steps_per_year;
			}

		}
	}
}
Пример #2
0
/* Called before and ALU clause starts for a wavefront */
void evg_isa_alu_clause_start(struct evg_wavefront_t *wavefront)
{
	/* Copy 'active' mask at the top of the stack to 'pred' mask */
	bit_map_copy(wavefront->pred, 0, wavefront->active_stack,
		wavefront->stack_top * wavefront->work_item_count, wavefront->work_item_count);
	if (debug_status(evg_isa_debug_category))
	{
		evg_isa_debug("  %s:pred=", wavefront->name);
		bit_map_dump(wavefront->pred, 0, wavefront->work_item_count,
			debug_file(evg_isa_debug_category));
	}

	/* Flag 'push_before_done' will be set by the first PRED_SET* inst */
	wavefront->push_before_done = 0;

	/* Stats */
	wavefront->alu_clause_count++;
}
Пример #3
0
void dir_entry_unlock(struct dir_t *dir, int x, int y)
{
	struct dir_lock_t *dir_lock;
	struct mod_stack_t *stack;
	FILE *f;

	/* Get lock */
	assert(x < dir->xsize && y < dir->ysize);
	dir_lock = &dir->dir_lock[x * dir->ysize + y];

	/* Wake up first waiter */
	if (dir_lock->lock_queue)
	{
		/* Debug */
		f = debug_file(mem_debug_category);
		if (f)
		{
			mem_debug("    A-%lld resumed", dir_lock->lock_queue->id);
			if (dir_lock->lock_queue->dir_lock_next)
			{
				mem_debug(" - {");
				for (stack = dir_lock->lock_queue->dir_lock_next; stack;
						stack = stack->dir_lock_next)
					mem_debug(" A-%lld", stack->id);
				mem_debug(" } still waiting");
			}
			mem_debug("\n");
		}

		/* Wake up access */
		esim_schedule_event(dir_lock->lock_queue->dir_lock_event, dir_lock->lock_queue, 1);
		dir_lock->lock_queue = dir_lock->lock_queue->dir_lock_next;
	}

	/* Trace */
	mem_trace("mem.end_access_block cache=\"%s\" access=\"A-%lld\" set=%d way=%d\n",
		dir->name, dir_lock->stack_id, x, y);

	/* Unlock entry */
	dir_lock->lock = 0;
}
Пример #4
0
int main(int argc, char* argv[])
{
    std::srand(time(nullptr));
    std::cout.sync_with_stdio(false);
    std::string server_address;
    if (argc<2)
    {
        server_address = "172.22.22.48";
        std::cout<<"using default server address: " + server_address <<std::endl;
    } else
    {
        server_address = argv[1];
    }
    CLIENT *pClient = CreateClient();
    /* for debugging:  */
    std::ifstream debug_file("test.txt");
    if (debug_file.is_open())
    {
        std::string line;
        std::vector<std::string> full;
        while (std::getline(debug_file, line))
        {
            full.push_back(line);
        }
        std::string resp = pClient->DebugResponse(full);
        std::cout<<"response: "<<resp <<std::endl;
    }
    /**/

    if (!pClient->Init(server_address))
    {
        std::cout<<"Connection failed"<<std::endl;
    } else
    {
        pClient->Run();
    }
    delete pClient;
    return 0;
}
Пример #5
0
/* FIXME - merge with ctx_execute */
void mips_isa_execute_inst(struct mips_ctx_t *ctx) {
  //	struct mips_regs_t *regs = ctx->regs;
  ctx->next_ip = ctx->n_next_ip;
  ctx->n_next_ip += 4;

  /* Debug */
  if (debug_status(mips_isa_inst_debug_category)) {
    mips_isa_inst_debug("%d %8lld %x: ", ctx->pid,
                        asEmu(mips_emu)->instructions, ctx->regs->pc);
    mips_inst_debug_dump(&ctx->inst, debug_file(mips_isa_inst_debug_category));
  }

  /* Call instruction emulation function */
  //	regs->pc = regs->pc + ctx->inst.info->size;
  if (ctx->inst.info->opcode) mips_isa_inst_func[ctx->inst.info->opcode](ctx);
  /* Statistics */
  mips_inst_freq[ctx->inst.info->opcode]++;

  /* Debug */
  mips_isa_inst_debug("\n");
  //	if (debug_status(mips_isa_call_debug_category))
  //		mips_isa_debug_call(ctx);
}
Пример #6
0
	double HydrogenBondSlick::updateScore()
	{
		Timer timer;
		timer.start();

#ifdef DEBUG
		Molecule debug_molecule;
#endif
		Size verbosity = getScoringFunction()->getOptions().getInteger(Option::VERBOSITY);

		score_ = 0.0;
		float val = 0.0;
		float distance;
		float angle;
		const Atom* hydrogen;
		const Atom* acceptor;
		Vector3 h_bond;
		Vector3 h_connection;

		// iterate over all possible hydrogen bond std::pairs
		vector< std::pair<const Atom*, const Atom*> >::const_iterator it;
		for (it = possible_hydrogen_bonds_.begin(); it != possible_hydrogen_bonds_.end(); ++it)
		{
			hydrogen = it->first;

			// we could check for multiple scoring here, but it would cost a lot
			// of performance.
			acceptor = it->second;

			// h_bond is the vector of the hbond
			h_bond = acceptor->getPosition() - hydrogen->getPosition();
			distance = fabs(ideal_hbond_length_ - h_bond.getLength());

			// if the distance is too large, the product of g1 and g2 is zero, so
			// we can skip the rest
			if (distance <= h_bond_distance_upper_)
			{
				// calculate g1
				val = getScoringFunction()->getBaseFunction()->calculate(distance, h_bond_distance_lower_, h_bond_distance_upper_);

				// calculate the angle of the hbond. It is necessary to find out
				// which one of the atoms is the actual hydrogen in order to
				// calculate the vector of the connection (in contrast to h bond)
				// of the hydrogen to the molecule it is attached to

				if (hydrogen->getElement().getSymbol() == "H")
				{
					h_connection =
						hydrogen->getBond(0)->getPartner(*hydrogen)->getPosition()
						- hydrogen->getPosition();
				}
				// PARANOIA
				else
				{
					Log.error() << "HydrogenBondSlick::updateEnergy(): "
						<< "black magic: hydrogen bond without hydrogens:" << std::endl
						<< hydrogen->getFullName() << ":" << acceptor->getFullName()
						<< std::endl;
					continue;
				}
				// /PARANOIA

				// angle is the angle of the h bond
				angle = ideal_hbond_angle_ - h_bond.getAngle(h_connection).toDegree();

				// if angle is too large, skip the rest
				if (angle <= h_bond_angle_upper_)
				{
					val *= getScoringFunction()->getBaseFunction()->calculate(angle,
							h_bond_angle_lower_, h_bond_angle_upper_);
#ifdef DEBUG
					Atom* atom_ptr_H = new Atom();
					atom_ptr_H->setElement(PTE[Element::Fe]);
					atom_ptr_H->setName("H");
					atom_ptr_H->setPosition(hydrogen->getPosition());
					atom_ptr_H->setCharge(val);

					Atom* atom_ptr_acceptor = new Atom();
					atom_ptr_acceptor->setElement(PTE[Element::Fe]);
					atom_ptr_acceptor->setName("ACC");
					atom_ptr_acceptor->setPosition(acceptor->getPosition());
					atom_ptr_acceptor->setCharge(val);

					Atom* atom_ptr_donor = new Atom();
					atom_ptr_donor->setElement(PTE[Element::Fe]);
					atom_ptr_donor->setName("DON");
					atom_ptr_donor->setPosition(hydrogen->getBond(0)->getPartner(*hydrogen)->getPosition());
					atom_ptr_donor->setCharge(val);

					atom_ptr_H->createBond(*atom_ptr_acceptor);
					atom_ptr_H->createBond(*atom_ptr_donor);

					debug_molecule.insert(*atom_ptr_H);
					debug_molecule.insert(*atom_ptr_acceptor);
					debug_molecule.insert(*atom_ptr_donor);
#endif

					// Print all single energy contributions
					if (verbosity >= 100)
					{
						Atom* donor = it->first->getBond(0)->getPartner(*it->first);
						Log.info() << "HB: " << val << " "
							<< donor->getFullName() << "-"
							<< it->first->getFullName();
						if (it->first->getResidue() != 0)
						{
							Log.info() << "[" << it->first->getResidue()->getID()
								<< "]";
						}
						Log.info() << "..."
							<< it->second->getFullName();
						if (it->second->getResidue() != 0)
						{
							Log.info() << "[" << it->second->getResidue()->getID()
								<< "]";
						}
						Log.info() << " (delta d " << distance
							<< ", delta phi " << angle << ")"
							<< std::endl;
					}
					score_ += val;
				}
			}
		}

		if (verbosity > 0)
		{
			Log.info() << "HB: energy is " << score_ << std::endl;
		}

#ifdef DEBUG
		HINFile debug_file("HB_debug.hin", std::ios::out);
		debug_file << debug_molecule;
		debug_file.close();
#endif

		timer.stop();
#ifdef DEBUG
		Log.info() << "HydrogenBondSlick::updateEnergy(): "
			<< timer.getCPUTime() << " s" << std::endl;
#endif

		return score_;
	}
Пример #7
0
int X86ThreadLookupTraceCache(X86Thread *self, unsigned int eip, int pred,
	int *ptr_mop_count, unsigned int **ptr_mop_array, unsigned int *ptr_neip)
{
	struct x86_trace_cache_t *trace_cache = self->trace_cache;
	struct x86_trace_cache_entry_t *entry;
	struct x86_trace_cache_entry_t *found_entry;

	unsigned int neip;

	int set;
	int way;
	int taken;

	FILE *f;

	/* Debug */
	if (x86_trace_cache_debugging())
	{
		f = debug_file(x86_trace_cache_debug_category);
		fprintf(f, "** Lookup **\n");
		fprintf(f, "eip = 0x%x, pred = ", eip);
		x86_trace_cache_pred_dump(pred, x86_trace_cache_branch_max, f);
		fprintf(f, "\n");
	}

	/* Look for trace cache line */
	found_entry = NULL;
	set = eip % x86_trace_cache_num_sets;
	for (way = 0; way < x86_trace_cache_assoc; way++)
	{
		entry = X86_TRACE_CACHE_ENTRY(set, way);
		if (entry->tag == eip && ((pred & entry->branch_mask) == entry->branch_flags))
		{
			found_entry = entry;
			break;
		}
	}

	/* Statistics */
	trace_cache->accesses++;
	if (found_entry)
		trace_cache->hits++;

	/* Miss */
	if (!found_entry)
	{
		x86_trace_cache_debug("Miss\n");
		x86_trace_cache_debug("\n");
		return 0;
	}
	
	/* Calculate address of the next instruction to fetch after this trace.
	 * The 'neip' value will be the trace 'target' if the last instruction in
	 * the trace is a branch and 'pred' predicts it taken. */
	taken = found_entry->target && (pred & (1 << found_entry->branch_count));
	neip = taken ? found_entry->target : found_entry->fall_through;

	/* Debug */
	if (x86_trace_cache_debugging())
	{
		f = debug_file(x86_trace_cache_debug_category);
		fprintf(f, "Hit - Set = %d, Way = %d\n", set, way);
		X86ThraceDumpTraceCacheEntry(self, found_entry, f);
		fprintf(f, "Next trace prediction = %c\n", taken ? 'T' : 'n');
		fprintf(f, "Next fetch address = 0x%x\n", neip);
		fprintf(f, "\n");
	}

	/* Return fields. */
	PTR_ASSIGN(ptr_mop_count, found_entry->mop_count);
	PTR_ASSIGN(ptr_mop_array, found_entry->mop_array);
	PTR_ASSIGN(ptr_neip, neip);

	/* Hit */
	return 1;
}
Пример #8
0
/* Flush temporary trace of committed instructions back into the trace cache */
static void X86ThreadFlushTraceCache(X86Thread *self)
{
	struct x86_trace_cache_t *trace_cache = self->trace_cache;
	struct x86_trace_cache_entry_t *entry;
	struct x86_trace_cache_entry_t *found_entry;
	struct x86_trace_cache_entry_t *trace = trace_cache->temp;

	int set;
	int way;
	int found_way;

	/* There must be something to commit */
	if (!trace->uop_count)
		return;

	/* If last instruction was a branch, remove it from the mask and flags fields,
	 * since this prediction does not affect the trace. Instead, the 'target'
	 * field of the trace cache line will be stored. */
	assert(trace->tag);
	if (trace->target)
	{
		assert(trace->branch_count);
		trace->branch_count--;
		trace->branch_mask &= ~(1 << trace->branch_count);
		trace->branch_flags &= ~(1 << trace->branch_count);
	}

	/* Allocate new line for the trace. If trace is already in the cache,
	 * do nothing. If there is any invalid entry, choose it. */
	found_entry = NULL;
	found_way = -1;
	set = trace->tag % x86_trace_cache_num_sets;
	for (way = 0; way < x86_trace_cache_assoc; way++)
	{
		/* Invalid entry found. Since an invalid entry should appear
		 * consecutively and at the end of the set, there is no hope
		 * that the trace will be in a later way. Stop here. */
		entry = X86_TRACE_CACHE_ENTRY(set, way);
		if (!entry->tag)
		{
			found_entry = entry;
			found_way = way;
			break;
		}

		/* Hit */
		if (entry->tag == trace->tag && entry->branch_mask == trace->branch_mask
			&& entry->branch_flags == trace->branch_flags)
		{
			found_entry = entry;
			found_way = way;
			break;
		}
	}

	/* If no invalid entry found, look for LRU. */
	if (!found_entry)
	{
		for (way = 0; way < x86_trace_cache_assoc; way++)
		{
			entry = X86_TRACE_CACHE_ENTRY(set, way);
			entry->counter--;
			if (entry->counter < 0)
			{
				entry->counter = x86_trace_cache_assoc - 1;
				found_entry = entry;
				found_way = way;
			}
		}
	}

	/* Flush temporary trace and reset it. When flushing, all fields are
	 * copied except for LRU counter. */
	assert(found_entry);
	assert(found_way >= 0);
	trace->counter = found_entry->counter;
	memcpy(found_entry, trace, X86_TRACE_CACHE_ENTRY_SIZE);
	memset(trace_cache->temp, 0, X86_TRACE_CACHE_ENTRY_SIZE);

	/* Debug */
	if (x86_trace_cache_debugging())
	{
		FILE *f;

		f = debug_file(x86_trace_cache_debug_category);
		fprintf(f, "** Commit trace **\n");
		fprintf(f, "Set = %d, Way = %d\n", set, found_way);
		X86ThraceDumpTraceCacheEntry(self, found_entry, f);
		fprintf(f, "\n");
	}

	/* Statistics */
	trace_cache->trace_length_acc += found_entry->uop_count;
	trace_cache->trace_length_count++;
}
Пример #9
0
void evg_isa_write_task_commit(struct evg_work_item_t *work_item)
{
	struct linked_list_t *task_list = work_item->write_task_list;
	struct evg_wavefront_t *wavefront = work_item->wavefront;
	struct evg_work_group_t *work_group = work_item->work_group;

	struct evg_isa_write_task_t *wt;
	struct evg_inst_t *inst;

	/* Process first tasks of type:
	 *  - EVG_ISA_WRITE_TASK_WRITE_DEST
	 *  - EVG_ISA_WRITE_TASK_WRITE_LDS
	 */
	for (linked_list_head(task_list); !linked_list_is_end(task_list); )
	{

		/* Get task */
		wt = linked_list_get(task_list);
		assert(wt->work_item == work_item);
		inst = wt->inst;

		switch (wt->kind)
		{
		
		case EVG_ISA_WRITE_TASK_WRITE_DEST:
		{
			if (wt->write_mask)
				evg_isa_write_gpr(work_item, wt->gpr, wt->rel, wt->chan, wt->value);
			work_item->pv.elem[wt->inst->alu] = wt->value;

			/* Debug */
			if (evg_isa_debugging())
			{
				evg_isa_debug("  i%d:%s", work_item->id,
					map_value(&evg_pv_map, wt->inst->alu));
				if (wt->write_mask)
				{
					evg_isa_debug(",");
					evg_inst_dump_gpr(wt->gpr, wt->rel, wt->chan, 0,
						debug_file(evg_isa_debug_category));
				}
				evg_isa_debug("<=");
				gpu_isa_dest_value_dump(inst, &wt->value,
					debug_file(evg_isa_debug_category));
			}

			break;
		}

		case EVG_ISA_WRITE_TASK_WRITE_LDS:
		{
			struct mem_t *local_mem;
			union evg_reg_t lds_value;

			local_mem = work_group->local_mem;
			assert(local_mem);
			assert(wt->lds_value_size);
			mem_write(local_mem, wt->lds_addr, wt->lds_value_size, &wt->lds_value);

			/* Debug */
			lds_value.as_uint = wt->lds_value;
			evg_isa_debug("  i%d:LDS[0x%x]<=(%u,%gf) (%d bytes)", work_item->id, wt->lds_addr,
				lds_value.as_uint, lds_value.as_float, (int) wt->lds_value_size);
			break;
		}

		default:
			linked_list_next(task_list);
			continue;
		}

		/* Done with this task */
		repos_free_object(evg_isa_write_task_repos, wt);
		linked_list_remove(task_list);
	}

	/* Process PUSH_BEFORE, PRED_SET */
	for (linked_list_head(task_list); !linked_list_is_end(task_list); )
	{
		/* Get task */
		wt = linked_list_get(task_list);
		inst = wt->inst;

		/* Process */
		switch (wt->kind)
		{

		case EVG_ISA_WRITE_TASK_PUSH_BEFORE:
		{
			if (!wavefront->push_before_done)
				evg_wavefront_stack_push(wavefront);
			wavefront->push_before_done = 1;
			break;
		}

		case EVG_ISA_WRITE_TASK_SET_PRED:
		{
			int update_pred = EVG_ALU_WORD1_OP2.update_pred;
			int update_exec_mask = EVG_ALU_WORD1_OP2.update_exec_mask;

			assert(inst->info->fmt[1] == EVG_FMT_ALU_WORD1_OP2);
			if (update_pred)
				evg_work_item_set_pred(work_item, wt->cond);
			if (update_exec_mask)
				evg_work_item_set_active(work_item, wt->cond);

			/* Debug */
			if (debug_status(evg_isa_debug_category))
			{
				if (update_pred && update_exec_mask)
					evg_isa_debug("  i%d:act/pred<=%d", work_item->id, wt->cond);
				else if (update_pred)
					evg_isa_debug("  i%d:pred=%d", work_item->id, wt->cond);
				else if (update_exec_mask)
					evg_isa_debug("  i%d:pred=%d", work_item->id, wt->cond);
			}
			break;
		}

		default:
			abort();
		}
		
		/* Done with task */
		repos_free_object(evg_isa_write_task_repos, wt);
		linked_list_remove(task_list);
	}

	/* List should be empty */
	assert(!linked_list_count(task_list));
}