예제 #1
0
파일: main.cpp 프로젝트: NicholasRoge/ncon
int main(int argc,char** argv){
	LoadNcon(argc,argv);
	char file_type;
	
	if(argc>2){
		if(strcmp(argv[2],"--sys-help")==0){
			return 100;
		}
		
		String cd_dir=getAbsoluteLocation(argv[argc-1],false);  //The directory that the user wants to change to will always be the last argument
		String absolute_cd_dir=getAbsoluteLocation(cd_dir);

		if(FileExists(absolute_cd_dir,&file_type)){
			if(file_type=='D'){
				setEnv("CWD",cd_dir);
			}else{
				printf("\"%s\" is not a directory.\n",(char*)cd_dir);
			}
		}else{
			printf("Directory \"%s\" does not exist.\n",(char*)cd_dir);
		}
	}else{
		printf("The \"cd\" command requires at least one parameter to execute.  Type \"cd --help\" for usage.\n");
	}
	return 0;
}
예제 #2
0
	/*********************************************************************************
	 *	Returns the location in the traceFile of the trace data (time stamp and cpid)
	 *	Precondition: the location of the trace data is between minLoc and maxLoc.
	 * @param time: the time to be found
	 * @param left_boundary_offset: the start location. 0 means the beginning of the data in a process
	 * @param right_boundary_offset: the end location.
	 ********************************************************************************/
	FileOffset TraceDataByRank::findTimeInInterval(Time time, FileOffset l_boundOffset,
			FileOffset r_boundOffset)
	{
		if (l_boundOffset == r_boundOffset)
			return l_boundOffset;



		FileOffset l_index = getRelativeLocation(l_boundOffset);
		FileOffset r_index = getRelativeLocation(r_boundOffset);

		Time l_time = data->getLong(l_boundOffset);
		Time r_time = data->getLong(r_boundOffset);
	
		// apply "Newton's method" to find target time
		while (r_index - l_index > 1)
		{
			FileOffset predicted_index;
			//pat2 7/1/13: We only ever divide by rate, and double multiplication
			//is faster than division (confirmed with a benchmark) so compute inverse
			//rate instead. This line of code and the one in the else block account for
			//about 40% of the computation once the data is in memory
			//double rate = (r_time - l_time) / (r_index - l_index);
			double invrate = (r_index - l_index) / (r_time - l_time);
			Time mtime = (r_time - l_time) / 2;
			if (time <= mtime)
			{
				predicted_index = max((Long) ((time - l_time) * invrate) + l_index, l_index);
			}
			else
			{
				predicted_index = min((r_index - (long) ((r_time - time) * invrate)), r_index);
			}
			// adjust so that the predicted index differs from both ends
			// except in the case where the interval is of length only 1
			// this helps us achieve the convergence condition
			if (predicted_index <= l_index)
				predicted_index = l_index + 1;
			if (predicted_index >= r_index)
				predicted_index = r_index - 1;

			Time temp = data->getLong(getAbsoluteLocation(predicted_index));
			if (time >= temp)
			{
				l_index = predicted_index;
				l_time = temp;
			}
			else
			{
				r_index = predicted_index;
				r_time = temp;
			}
		}
		FileOffset l_offset = getAbsoluteLocation(l_index);
		FileOffset r_offset = getAbsoluteLocation(r_index);

		l_time = data->getLong(l_offset);
		r_time = data->getLong(r_offset);

		int leftDiff = time - l_time;
		int rightDiff = r_time - time;
		 bool is_left_closer = abs(leftDiff) < abs(rightDiff);
		if (is_left_closer)
			return l_offset;
		else if (r_offset < maxloc)
			return r_offset;
		else
			return maxloc;
	}