• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetTimeMs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GetTimeMs函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTimeMs函数的具体用法?C++ GetTimeMs怎么用?C++ GetTimeMs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetTimeMs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PerftTest

void PerftTest(int depth, S_BOARD *pos) {
	S_MOVELIST list[1];
	int move;
	int MoveNum = 0;
	int start = GetTimeMs();
	long cumnodes, oldnodes;

	ASSERT(CheckBoard(pos));

	PrintBoard(pos);
	printf("\nStarting Test To Depth:%d\n", depth);
	leafNodes = 0;
	
	GenerateAllMoves(pos, list);

	for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
		move = list->moves[MoveNum].move;
		if(!MakeMove(pos, move))
			continue;

		cumnodes = leafNodes;
		Perft(depth - 1, pos);
		TakeMove(pos);
		oldnodes = leafNodes - cumnodes;
		printf("move %d : %s : %ld\n", MoveNum + 1, PrMove(move), oldnodes);
	}

	printf("\nTest Complete : %ld nodes visited in %dms\n", leafNodes, GetTimeMs() - start);
}
开发者ID:peterwankman,项目名称:vice,代码行数:29,代码来源:perft.c


示例2: tcp_client

void* tcp_client(void *whatever){

	struct sockaddr_in server_addr;
	int sckt, status, len;
	int starttime, stoptime;
	struct hostent *server;
	int iSetOption = 1;

	sckt = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (char*)&iSetOption, sizeof(iSetOption));

	if(sckt == -1)
	{
	    printf("error opening socket\n");
	    exit(EXIT_FAILURE);
	}

    if (h.server == NULL) {
        fprintf(stderr,"Cannot connect to the server\n");
        exit(EXIT_FAILURE);
    }

	server_addr.sin_port = htons(h.port);
	memcpy(&server_addr.sin_addr.s_addr, h.server->h_addr, h.server->h_length);
	server_addr.sin_family = AF_INET;

	if (connect(sckt,(struct sockaddr *) &server_addr,sizeof(server_addr)) < 0) {
		printf("Couldn't connect\n");
    	exit(EXIT_FAILURE);
	}

	starttime = GetTimeMs();
	status = write(sckt, h.buffer, lSize);
	if (status < 0){
	  	printf("Couldn't write the message\n");
	   	exit(EXIT_FAILURE);
	}
	stoptime = GetTimeMs();	    

    printf("Duration client write = %d us\n", stoptime - starttime);

    //sleep(2);

    starttime = GetTimeMs();
    char *message = (char *)calloc( 1, lSize+1 );
    status = read(sckt,message,lSize);
    if (status < 0){
    	printf("Cannot read from the socket\n");
    	exit(EXIT_FAILURE);
    }
    stoptime = GetTimeMs();

    printf("Duration client read back = %d us\n", stoptime - starttime);
    //printf("%s\n", message);

	close(sckt);
	pthread_exit(NULL);
	exit(EXIT_SUCCESS);
}
开发者ID:gmendonca,项目名称:network-socket-speed,代码行数:59,代码来源:bettertcp.cpp


示例3: DisplaySubWindow

// Callback function called by GLUT to render sub-window content
void DisplaySubWindow(void)
{
    float v[4]; // will be used to set light parameters
    float mat[4*4]; // rotation matrix
    SubWindowData *win;

    win = GetCurrentSubWindowData();
    if (win == NULL) return;

    // Tell AntTweakBar which is the current window
    TwSetCurrentWindow(win->WinID);

    // Clear frame buffer
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_NORMALIZE);

    // Set light
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    v[0] = v[1] = v[2] = win->LightMultiplier*0.4f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_AMBIENT, v);
    v[0] = v[1] = v[2] = win->LightMultiplier*0.8f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
    v[0] = -win->LightDirection[0]; v[1] = -win->LightDirection[1]; v[2] = -win->LightDirection[2]; v[3] = 0.0f;
    glLightfv(GL_LIGHT0, GL_POSITION, v);

    // Set material
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, win->MatAmbient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, win->MatDiffuse);

    // Rotate and draw shape
    glPushMatrix();
    glTranslatef(0.5f, -0.3f, 0.0f);
    if( win->AutoRotate ) 
    {
        float axis[3] = { 0, 1, 0 };
        float angle = (float)(GetTimeMs()-win->RotateTime)/1000.0f;
        float quat[4];
        SetQuaternionFromAxisAngle(axis, angle, quat);
        MultiplyQuaternions(win->RotateStart, quat, win->Rotation);
    }
    ConvertQuaternionToMatrix(win->Rotation, mat);
    glMultMatrixf(mat);
    glScalef(win->Zoom, win->Zoom, win->Zoom);
    glCallList(win->ObjectShape);
    glPopMatrix();

    // Draw tweak bars
    TwDraw();

    // Present frame buffer
    glutSwapBuffers();

    // Recall Display at next frame
    glutPostRedisplay();
}
开发者ID:AGoodGameMaker,项目名称:opengl-tutorial-org,代码行数:61,代码来源:TwDualGLUT.c


示例4: DebugAnalysisTest

void DebugAnalysisTest(S_BOARD *pos, S_SEARCHINFO *info) {

	FILE *file;
    file = fopen("lct2.epd","r");
    char lineIn [1024];

	info->depth = MAXDEPTH;
	info->timeset = TRUE;
	int time = 1140000;


    if(file == NULL) {
        printf("File Not Found\n");
        return;
    }  else {
        while(fgets (lineIn , 1024 , file) != NULL) {
			info->starttime = GetTimeMs();
			info->stoptime = info->starttime + time;
			ClearHashTable(pos->HashTable);
            ParseFen(lineIn, pos);
            printf("\n%s\n",lineIn);
			printf("time:%d start:%d stop:%d depth:%d timeset:%d\n",
				time,info->starttime,info->stoptime,info->depth,info->timeset);
			SearchPosition(pos, info);
            memset(&lineIn[0], 0, sizeof(lineIn));
        }
    }
}
开发者ID:alankar63,项目名称:chess-engine,代码行数:28,代码来源:validate.c


示例5: return

// Get the time elapsed since the Start()
u64 Timer::GetTimeElapsed()
{
	// If we have not started yet, return 1 (because then I don't
	// have to change the FPS calculation in CoreRerecording.cpp .
	if (m_StartTime == 0) return 1;

	// Return the final timer time if the timer is stopped
	if (!m_Running) return (m_LastTime - m_StartTime);

	return (GetTimeMs() - m_StartTime);
}
开发者ID:Ced2911,项目名称:ppsspp,代码行数:12,代码来源:Timer.cpp


示例6: IB_Animate_Sleep

static void
IB_Animate_Sleep(unsigned int t0, double a)
{
   unsigned int        t;
   double              dt;

   t = GetTimeMs() - t0;
   dt = 1e-3 * (t - a * IB_ANIM_TIME);
   dt = 1e-3 * IB_ANIM_STEP - dt;
   if (dt > 0)
      usleep((unsigned long)(1e6 * dt));
}
开发者ID:Limsik,项目名称:e17,代码行数:12,代码来源:iconify.c


示例7: SetAutoRotateCB

void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{

	g_AutoRotate = *(const int *)value;
	if (g_AutoRotate != 0)
	{
		g_RotateTime = GetTimeMs();
		g_RotateStart[0] = g_Rotation[0];
		g_RotateStart[1] = g_Rotation[1];
		g_RotateStart[2] = g_Rotation[2];
		g_RotateStart[3] = g_Rotation[3];
		TwDefine(" TweakBar/ObjRotation readonly ");
	}
	else
		TwDefine(" TweakBar/ObjRotation readwrite ");
}
开发者ID:rashikamishra,项目名称:CS-6323,代码行数:16,代码来源:Main.cpp


示例8: SetAutoRotateCB

//  Callback function called when the 'AutoRotate' variable value of the tweak bar has changed
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
	(void)clientData; // unused

	g_AutoRotate = *(const int *)value; // copy value to g_AutoRotate
	if (g_AutoRotate != 0)
	{
		// init rotation
		g_RotateTime = GetTimeMs();
		g_RotateStart[0] = g_Rotation[0];
		g_RotateStart[1] = g_Rotation[1];
		g_RotateStart[2] = g_Rotation[2];
		g_RotateStart[3] = g_Rotation[3];

		// make Rotation variable read-only
		TwDefine(" TweakBar/ObjRotation readonly ");
	}
	else
		// make Rotation variable read-write
		TwDefine(" TweakBar/ObjRotation readwrite ");
}
开发者ID:Sylvanuszhy,项目名称:IBL,代码行数:22,代码来源:main.cpp


示例9: SetAutoRotateCB

//  Callback function called when the 'AutoRotate' variable value of the tweak bar has changed
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
	SubWindowData *win;
	
	win = (SubWindowData *)clientData;
    win->AutoRotate = *(const int *)value; // copy value to win->AutoRotate

    if (win->AutoRotate != 0) 
    {
        // init rotation
        win->RotateTime = GetTimeMs();
        win->RotateStart[0] = win->Rotation[0];
        win->RotateStart[1] = win->Rotation[1];
        win->RotateStart[2] = win->Rotation[2];
        win->RotateStart[3] = win->Rotation[3];
    }

    // make Rotation variable read-only or read-write
    TwSetCurrentWindow(win->WinID);
    TwSetParam(win->Bar, "ObjRotation", "readonly", TW_PARAM_INT32, 1, &win->AutoRotate);
}
开发者ID:AGoodGameMaker,项目名称:opengl-tutorial-org,代码行数:22,代码来源:TwDualGLUT.c


示例10: GetTimeMs

// Get the formatted time elapsed since the Start()
std::string Timer::GetTimeElapsedFormatted() const
{
	// If we have not started yet, return zero
	if (m_StartTime == 0)
		return "00:00:00:000";

	// The number of milliseconds since the start.
	// Use a different value if the timer is stopped.
	u64 Milliseconds;
	if (m_Running)
		Milliseconds = GetTimeMs() - m_StartTime;
	else
		Milliseconds = m_LastTime - m_StartTime;
	// Seconds
	u32 Seconds = (u32)(Milliseconds / 1000);
	// Minutes
	u32 Minutes = Seconds / 60;
	// Hours
	u32 Hours = Minutes / 60;

	std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i",
		Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000);
	return TmpStr;
}
开发者ID:Ced2911,项目名称:ppsspp,代码行数:25,代码来源:Timer.cpp


示例11: overlap

void overlap() { 
  Globals::qbs = new QNode*[Globals::threads_num];
  Globals::sets = new std::map<myset,myset*>[Globals::threads_num];
  for (int i = 0; i<Globals::threads_num; i++) {
    Globals::qbs[i] = new QNode();
  }

  denominator = Globals::c2 * Globals::gamma; 
  denominator /= Globals::side_multiplier;
  
  boost::thread* thr[Globals::threads_num];
  for (int i = 0; i < Globals::threads_num; ++i)
    thr[i] = new boost::thread(Worker(i));
  for (int i = 0; i < Globals::threads_num; ++i) {
    thr[i]->join();
    delete thr[i];
  }
 
//  for (int i=0; i<Globals::threads_num; i++) {
//    rec_count(Globals::qbs[i], 1.0);
//    std::cout << Globals::ov_nodes << " " << Globals::ov_leaves << std::endl;
//    Globals::ov_nodes=1;
//    Globals::ov_leaves=0;
//  }
 
  double merging_timer = GetTimeMs();
  for (int i=1; i<Globals::threads_num; i++) {
    std::cout << "Merging " << i << std::endl;
    merge_nodes(Globals::qbs[0],Globals::qbs[i]);
    delete Globals::qbs[i];
  }
  Globals::qb = Globals::qbs[0];
  //depth_all_reprs(Globals::qb);
  make_it_deeper(Globals::qb);

  //TODO
  //std::cout << "start filling" << std::endl;

//  std::cout << "before fill vectors" << std::endl;
//  fill_vectors(Globals::qb, &Globals::hypercube_center, 1.0);

/*  for (int i=0; i<10; i++) {
    printPt(std::cout,*Globals::qt_centers[i]);
    std::cout<<std::endl;
    std::cout << Globals::qt_sides[i] << std::endl;
  }*/

  Globals::ov_nodes=1;
  Globals::ov_leaves=0;
  rec_count(Globals::qb);
  //TODO
  ////std::cout << " ovnodes " << Globals::ov_nodes << " " << Globals::ov_leaves << std::endl;
  ////std::cout << "LEAF: " << couter << std::endl;

  dothereprs();

ANNmin_k* asdf = new ANNmin_k(1);

//  fill_in_reprs(Globals::qb, &Globals::hypercube_center, 1.0, Globals::kdtree, asdf);
  find_all_reprs(Globals::qbs[0], &Globals::hypercube_center, 1.0, Globals::kdtree, asdf,0);

  Globals::merging_time = GetTimeMs() - merging_timer;

  ANNidxArray  nnIdx = new ANNidx[Globals::reprs_num];
  ANNdistArray dists = new ANNdist[Globals::reprs_num];
  //replace_reprs(Globals::qb, &Globals::hypercube_center, 1.0, nnIdx, dists); CHANGE
  delete[] nnIdx;
  delete[] dists; 
//TODO
//  std::cout << "done replacing" << std::endl; 
  /*std::map<myset,myset*>::iterator it;
  for (int i=0; i<Globals::threads_num; i++) {
    for (it=Globals::sets[i].begin(); it!=Globals::sets[i].end(); it++) {
      delete (*it).second;
    }
  }*/
  delete[] Globals::sets;

  //representatives();
}
开发者ID:akonskarm,项目名称:avdpp,代码行数:80,代码来源:overlap.cpp


示例12: printf

void IO::consoleLoop(Board* board, SEARCHINFO* info) {
    printf("Welcome to TidesTicTactics in Console Mode!\n");
    info->POST_THINKING = true;
    setbuf(stdin, NULL);
    setbuf(stdin, NULL);
    int depth = 81;
    int movetime = 500; // 3 sec
    Coordinate move;
    char inBuf[80], command[80], modifier[80];
    Color engineSide = COLOR_NONE;
    Engine engine;
    Movelist movecheck;
    bool init = false;
    bool initX = true;
    Movelist movelist;

    while (true) {
        fflush(stdout);
        if ((board->toMove == engineSide || engineSide == COLOR_BOTH) && board->winner == COLOR_NONE) {
            info->starttime = GetTimeMs();
            info->depth = depth;
            if (movetime != 0) {
                info->timeset = true;
                info->stoptime = info->starttime + movetime;
            }
            engine.searchPosition(board, info, true);
            engineSide = COLOR_NONE;
        }
        // print prompt
        printf("");
        fflush(stdout);
        memset(&inBuf[0], 0, sizeof(inBuf));
        fflush(stdout);
        if(!fgets(inBuf, 80, stdin))
            continue;
        std::transform(inBuf, inBuf + 80 - 1, inBuf, [](unsigned char c) { return std::tolower(c); });
        sscanf(inBuf, "%s", command);

        if(!strcmp(command, "help")) {
            printf("\nCommands:\n");
            printf("quit - quit game\n");
            printf("force - will not move\n");
            printf("print - show board\n");
            printf("post - show thinking\n");
            printf("nopost - do not show thinking\n");
            printf("new - start new game\n");
            printf("go - set computer thinking\n");
            printf("depth x - set depth to x\n");
            printf("time x - set thinking time to x seconds (depth still applies if set)\n");
            printf("view - show current depth and movetime settings\n");
            printf("moves - show valid moves\n");
            printf("captures - show moves winning a board");
            printf("test x - load first x moves of demo");
            printf("test2 x - load first x moves of demo");
            printf("** note ** - to reset time and depth, set to 0\n");
            printf("enter moves using B1..9F1..9 notation\n\n\n");
            continue;
        }

        if(!strcmp(command, "moves")) {
            board->getMoves(&movecheck);
            if (movecheck.count == 0) {
                printf("No moves found");
            }
            for(int i = 0; i < movecheck.count; i++) {
                printf("%s ", PRMOVE(movecheck.moves[i].move).c_str());
            }
            printf("\n");
            continue;
        }

        if(!strcmp(command, "player")) {
            sscanf(inBuf, "player %s init", modifier);
            if(!strcmp(modifier, "one")) {
                init = true;
                initX = true;
            } else if(!strcmp(modifier, "two")) {
                init = true;
                initX = false;
            } else {
                printf("unknown player: %s\n", modifier);
            }
            continue;
        }

        if(!strcmp(command, "start")) {
            sscanf(inBuf, "start %s", modifier);
            if(!strcmp(modifier, "turns")) {
                init = false;
                board->toMove = COLOR_X;
                board->next = SQUARE_NONE;
            } else if(!strcmp(modifier, "game")) {
                init = true;
            } else {
                printf("unknown start modifier: %s\n", modifier);
            }
            continue;
        }

        if(!strcmp(command, "captures")) {
//.........这里部分代码省略.........
开发者ID:TurnTheTideTM,项目名称:TidesTicTactics,代码行数:101,代码来源:IO.cpp


示例13: main


//.........这里部分代码省略.........
	glutCreateWindow("SRTP Middle Check");
	glutCreateMenu(NULL);
	glewInit();
	initTextureList();
	for (int i = 0; i < textpoint; i++){
		glActiveTexture(GL_TEXTURE0 + i);
		glBindTexture(GL_TEXTURE_2D, textureObjects[i]);
	}
	glActiveTexture(GL_TEXTURE0);

	sprintf(path, "%sCook-Torrorence", root);
	programs[2] = setupShaders(path);

	// Set GLUT callbacks
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);

	// Initialize AntTweakBar
	TwInit(TW_OPENGL, NULL);

	// Set GLUT event callbacks
	// - Directly redirect GLUT mouse button events to AntTweakBar
	glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
	// - Directly redirect GLUT mouse motion events to AntTweakBar
	glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT key events to AntTweakBar
	glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
	// - Directly redirect GLUT special key events to AntTweakBar
	glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
	// - Send 'glutGetModifers' function pointer to AntTweakBar;
	//   required because the GLUT key event functions do not report key modifiers states.
	TwGLUTModifiersFunc(glutGetModifiers);

	// Create some 3D objects (stored in display lists)
	glNewList(SHAPE_TEAPOT, GL_COMPILE);
	glutSolidTeapot(1.0);
	glEndList();
	glNewList(SHAPE_TORUS, GL_COMPILE);
	//glutSolidTorus(0.3, 1.0, 16, 32);
	glutSolidSphere(0.75f, 20, 20);
	glEndList();
	glNewList(SHAPE_DRAGON, GL_COMPILE);
	drawBunny("dragon");
	glEndList();
	glNewList(SHAPE_SKULL, GL_COMPILE);
	drawBunny("skull");
	glEndList();
	glNewList(SHAPE_GARGO, GL_COMPILE);
	drawBunny("Gargoyle_ABF");
	glEndList();
	glNewList(DRAW_EN, GL_COMPILE);
	drawEnv(30);
	glEndList();

	// Create a tweak bar
	bar = TwNewBar("TweakBar");
	TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
	TwDefine(" TweakBar size='250 540' color='96 216 224' "); // change default tweak bar size and color

	TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=7.5 step=0.01 ");
	TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true ");
	TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space ");
	TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &lightDirection, " label='Light direction' opened=true ");
	TwAddVarRW(bar, "LightDist", TW_TYPE_FLOAT, &lightDistance, " label='Light distance' ");
	TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &lightAmbient, "");
	TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &lightDiffuse, "");
	TwAddVarRW(bar, "Rf", TW_TYPE_COLOR3F, &rf, "");
	TwAddVarRW(bar, "Roughness", TW_TYPE_FLOAT, &roughness, " label='Roughness' min=0.01 max=1.99 step=0.01 keyIncr='+' keyDecr='-' ");

	{
		TwEnumVal shaders[NUM_SHADERS] = { { SHADER_PHONG, "Phong" }, { SHADER_COOKTORRORENCE, "CookTorrorence" } };
		TwType shaderType = TwDefineEnum("ShaderType", shaders, NUM_SHADERS);
		TwAddVarRW(bar, "Shader", shaderType, &currentShader, "");
	}

	// Add the enum variable 'g_CurrentShape' to 'bar'
	// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
	{
		// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
		TwEnumVal shapeEV[NUM_SHAPES] = { { SHAPE_TEAPOT, "Teapot" }, { SHAPE_TORUS, "Sphere" }, { SHAPE_DRAGON, "Dragon" }, { SHAPE_SKULL, "Skull" }, { SHAPE_GARGO, "Gargo" } };
		// Create a type for the enum shapeEV
		TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
		// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
		TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, "");
	}

	// Store time
	g_RotateTime = GetTimeMs();
	// Init rotation
	SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
	SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

	atexit(Terminate);  // Called after glutMainLoop ends
	// Call the GLUT main loop
	glutMainLoop();

	return 0;
}
开发者ID:Sylvanuszhy,项目名称:IBL,代码行数:101,代码来源:main.cpp


示例14: main

   int main() {

         // Create the variables for the time measure
         int starttime, stoptime;

         //Get initial time
         starttime = GetTimeMs();

         // This code executes on the OpenCL host

         // Host data
         float *A=NULL; // Input array
         float *B=NULL; // Input array
         float *C=NULL; // Output array

         // Elements in each array
          const int elements=2048;
         // Compute the size of the data
         size_t datasize=sizeof(int)*elements;

         // Allocate space for input/output data
         A=(float*)malloc(datasize);
         B=(float*)malloc(datasize);
         C=(float*)malloc(datasize);

         // Initialize the input data
         A[0]=2.2;
         A[1]=1.3;
         B[0]=3.7;
         B[1]=5.4;


         // Load the kernel source code into the array programSource
	     FILE *fp;
	     char *programSource;
	     size_t programSize;
	 
	     fp = fopen("fplos_kernels.cl", "r");
	     if (!fp) {
	         fprintf(stderr, "Failed to load kernel.\n");
	         exit(1);
	     }
	     programSource = (char*)malloc(MAX_SOURCE_SIZE);
	     fclose( fp );

         // Use this to check the output of each API call
         cl_int status;

         // Retrieve the number of platforms
         cl_uint numPlatforms=0;
         status=clGetPlatformIDs(0, NULL,&numPlatforms);

         // Allocate enough space for each platform
         cl_platform_id *platforms=NULL;
         platforms=(cl_platform_id*)malloc(
              numPlatforms*sizeof(cl_platform_id));

         // Fill in the platforms
         status = clGetPlatformIDs(numPlatforms, platforms, NULL);

         // Retrieve the number of devices
         cl_uint numDevices=0;
         status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, 0,
               NULL,&numDevices);

         // Allocate enough space for each device
         cl_device_id *devices;
         devices = (cl_device_id*)malloc(
               numDevices*sizeof(cl_device_id));

         // Fill in the devices
         status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL,
              numDevices, devices, NULL);

         // Create a context and associate it with the devices
         cl_context context;
         context = clCreateContext(NULL, numDevices, devices, NULL,
             NULL, &status);

         // Create a command queue and associate it with the device
         cl_command_queue cmdQueue;
         cmdQueue = clCreateCommandQueue(context, devices[0], 0,
            &status);

         // Create a buffer object that will contain the data
         // from the host array A
         cl_mem bufA;
         bufA = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
             NULL, &status);

         // Create a buffer object that will contain the data
         // from the host array B
         cl_mem bufB;
         bufB = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
            NULL, &status);

         // Create a buffer object that will hold the output data
         cl_mem bufC;
         bufC = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize,
            NULL, &status);
//.........这里部分代码省略.........
开发者ID:gmendonca,项目名称:gpu-speed-bench,代码行数:101,代码来源:flopaddition.cpp


示例15: main

int main(int argc, char *argv[]){
	
	int t1,t2;
	int starttime, stoptime;
	pthread_t thread1, thread2;

	h.server = gethostbyname(argv[1]);
	h.port = atoi(argv[2]);

	FILE *fp;

	if(strcmp(argv[3], "1b") == 0)fp = fopen("../txt/1b.txt", "rb");
	else if(strcmp(argv[3], "1kb") == 0)fp = fopen("../txt/1kb.txt", "rb");
	else if(strcmp(argv[3], "64kb") == 0)fp = fopen("../txt/64kb.txt", "rb");
	else if(strcmp(argv[3], "1mb") == 0)fp = fopen("../txt/1mb.txt", "rb");
	else fp = fopen("../txt/alice.txt", "rb");

    if (!fp) {
        fprintf(stderr, "Failed to load file.\n");
        return -1;
    }

	fseek( fp , 0L , SEEK_END);
	lSize = ftell( fp );
	rewind( fp );

	/* allocate memory for entire content */
	h.buffer = (char *)calloc( 1, lSize+1 );
	if( !h.buffer ){
		fclose(fp);
		printf("Couldn't allocate memory\n");
		return -1;
	}

	/* copy the file into the buffer */
	if( fread( h.buffer , lSize, 1 , fp) != true){
		fclose(fp);
		free(h.buffer);
		printf("Couldn't copy in buffer\n");
		return -1;
	}

	fclose(fp);

	const char *message1 = "Thread 1";
	const char *message2 = "Thread 2";

	starttime = GetTimeMs();
	t1 = pthread_create(&thread1, NULL, tcp_server, (void *)message1);
    if (t1) {
        printf("ERROR; thread tcp_server");
        return -1;
    }

    t2 = pthread_create(&thread2, NULL, tcp_client, (void *)message2);
    if (t2) {
        printf("ERROR; thread tcp_client");
        return -1;
    }
	stoptime = GetTimeMs();

    //printf("Duration= %d us\n", stoptime - starttime);

	pthread_exit(NULL);
	return 0;
}
开发者ID:gmendonca,项目名称:network-socket-speed,代码行数:66,代码来源:bettertcp.cpp


示例16: Display

void Display(void)
{
	//display the background image here
	
	/*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 1, 0, 1, -1, 1);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glDepthMask(GL_FALSE);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glRasterPos2i(0, 0);
	glDrawPixels()*/

	/*
	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	*/
	//background();


		float v[4]; 
		float v1[4];
		float mat[4 * 4];

		glClearColor(0, 0, 0, 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glEnable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);
		glEnable(GL_NORMALIZE);

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f;
		glLightfv(GL_LIGHT0, GL_AMBIENT, v);
		v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f;
		glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
		v[0] = -g_LightDirection[0]; v[1] = -g_LightDirection[1]; v[2] = -g_LightDirection[2]; v[3] = 0.0f;
		glLightfv(GL_LIGHT0, GL_POSITION, v);
		

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT1);
		v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.4f; v1[3] = 1.0f;
		glLightfv(GL_LIGHT1, GL_AMBIENT, v1);
		v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.8f; v1[3] = 1.0f;
		glLightfv(GL_LIGHT1, GL_DIFFUSE, v1);
		v1[0] = -g_LightDirection2[0]; v1[1] = -g_LightDirection2[1]; v1[2] = -g_LightDirection2[2]; v1[3] = 0.0f;
		glLightfv(GL_LIGHT1, GL_POSITION, v1);

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient1);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse1);

		glPushMatrix();
		glTranslatef(0.5f, -0.3f, 0.0f);
		if (g_AutoRotate)
		{
			float axis[3] = { 0, 1, 0 };
			float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f;
			float quat[4];
			SetQuaternionFromAxisAngle(axis, angle, quat);
			MultiplyQuaternions(g_RotateStart, quat, g_Rotation);
		}
		ConvertQuaternionToMatrix(g_Rotation, mat);
		glMultMatrixf(mat);
		glScalef(g_Zoom, g_Zoom, g_Zoom);
		Matrices identity;
		animation->evaluate(newTime);
		if (animate){
			float timeDiff = currentTime - prevTime;
			prevTime = currentTime;
			currentTime = time(NULL);
			newTime = newTime + 0.01;
		}
		skeletonWasp->calculate(identity.IDENTITY);
		skinningWasp->update();
		skinningWasp->draw();		
		glPopMatrix();
	

	TwDraw();

	glutSwapBuffers();

	glutPostRedisplay();
}
开发者ID:rashikamishra,项目名称:CS-6323,代码行数:91,代码来源:Main.cpp


示例17: SetupSubWindow

// Setup new sub-window
void SetupSubWindow(int subWinIdx) 
{
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;
    SubWindowData *win;
    
    win = &g_SubWindowData[subWinIdx];
    win->ObjectShape = (subWinIdx == 0) ? SHAPE_TEAPOT : SHAPE_TORUS;
	win->Zoom = 1;
	win->AutoRotate = (subWinIdx == 0);
    win->MatAmbient[0] = (subWinIdx == 1) ? 0.0f : 0.5f;; win->MatAmbient[1] = win->MatAmbient[2] = 0.2f; win->MatAmbient[3] = 1;
    win->MatDiffuse[0] = (subWinIdx == 1) ? 0.0f : 1.0f; win->MatDiffuse[1] = 1; win->MatDiffuse[2] = 0; win->MatDiffuse[3] = 1;
	win->LightMultiplier = 1;
    win->LightDirection[0] = win->LightDirection[1] = win->LightDirection[2] = -0.57735f;
    win->RotateTime = GetTimeMs();
    SetQuaternionFromAxisAngle(axis, angle, win->Rotation);
    SetQuaternionFromAxisAngle(axis, angle, win->RotateStart);
	
	glutSetWindow(win->WinID);
    // Set GLUT callbacks
    glutDisplayFunc(DisplaySubWindow);
    glutReshapeFunc(ReshapeSubWindow);
    // Set GLUT event callbacks
    // - Register mouse button events callback
    glutMouseFunc((GLUTmousebuttonfun)MouseButtonCB);
    // - Register mouse motion events callback
    glutMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register mouse "passive" motion events (same as Motion)
    glutPassiveMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register keyboard events callback
    glutKeyboardFunc((GLUTkeyboardfun)KeyboardCB);
    // - Register special key events callback
    glutSpecialFunc((GLUTspecialfun)SpecialKeyCB);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Declare this window as current for AntTweakBar.
    // Here, this will create a new AntTweakBar context for this window,
    // which will be identified by the number WinID.
    TwSetCurrentWindow(win->WinID);

    // Create a tweak bar
    win->Bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to use AntTweakBar with multiple windows.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'win->Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(win->Bar, "Zoom", TW_TYPE_FLOAT, &win->Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'win->Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(win->Bar, "ObjRotation", TW_TYPE_QUAT4F, &win->Rotation, 
               " label='Object rotation' open help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(win->Bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, win, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'win->LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(win->Bar, "Multiplier", TW_TYPE_FLOAT, &win->LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'win->LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(win->Bar, "LightDir", TW_TYPE_DIR3F, &win->LightDirection, 
               " label='Light direction' open help='Change the light direction.' ");

    // Add 'win->MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(win->Bar, "Ambient", TW_TYPE_COLOR3F, &win->MatAmbient, " group='Material' ");

    // Add 'win->MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(win->Bar, "Diffuse", TW_TYPE_COLOR3F, &win->MatDiffuse, " group='Material' ");

    // Add the enum variable 'win->ObjectShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'win->CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(win->Bar, "Shape", shapeType, &win->ObjectShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }
}
开发者ID:AGoodGameMaker,项目名称:opengl-tutorial-org,代码行数:98,代码来源:TwDualGLUT.c


示例18: main

// Main
int main(int argc, char *argv[])
{
    TwBar *bar; // Pointer to the tweak bar
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar simple example using GLUT");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    atexit(Terminate);  // Called after glutMainLoop ends

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, 
               " label='Object rotation' opened=true help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, 
               " label='Light direction' opened=true help='Change the light direction.' ");

    // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");

    // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");

    // Add the enum variable 'g_CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }

    // Store time
    g_RotateTime = GetTimeMs();
    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

    // Call the GLUT main loop
    glutMainLoop();
//.........这里部分代码省略.........
开发者ID:AleiHanami,项目名称:OceanCurrents,代码行数:101,代码来源:TwSimpleGLUT.c


示例19: screen

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetTimeStamp函数代码示例发布时间:2022-05-30
下一篇:
C++ GetTimeInMillis函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap