Search Results

Search found 9 results on 1 pages for 'sagekilla'.

Page 1/1 | 1 

  • Creating an independent draw thread using pthreads (C++)

    - by sagekilla
    Hi all, I'm working on a graphical application which looks something like this: while (Simulator.simulating) { Simulator.update(); InputManager.processInput(); VideoManager.draw(); } I do this several times a second, and in the vast majority of cases my computation will be taking up 90 - 99% of my processing time. What I would like to do is take out the processInput and draw functions and have each one run independently. That way, I can have the input thread always checking for input (at a reasonable rate), and the draw thread attempting to redraw at a given frame rate. My issue is I'm not sure how I can properly do this. How would I properly initialize my pthread_t and associated pthread_attr_t so that the thread runs without blocking what I'm doing? Any help or even a link is appreciated, thanks!

    Read the article

  • Can my loop be optimized any more? (C++)

    - by Sagekilla
    Below is one of my inner loops that's run several thousand times, with input sizes of 20 - 1000 or more. Is there anything I can do to help squeeze any more performance out of this? I'm not looking to move this code to something like using tree codes (Barnes-Hut), but towards optimizing the actual calculations happening inside, since the same calculations occur in the Barnes-Hut algorithm. Any help is appreciated! typedef double real; struct Particle { Vector pos, vel, acc, jerk; Vector oldPos, oldVel, oldAcc, oldJerk; real mass; }; class Vector { private: real vec[3]; public: // Operators defined here }; real Gravity::interact(Particle *p, size_t numParticles) { PROFILE_FUNC(); real tau_q = 1e300; for (size_t i = 0; i < numParticles; i++) { p[i].jerk = 0; p[i].acc = 0; } for (size_t i = 0; i < numParticles; i++) { for (size_t j = i+1; j < numParticles; j++) { Vector r = p[j].pos - p[i].pos; Vector v = p[j].vel - p[i].vel; real r2 = lengthsq(r); real v2 = lengthsq(v); // Calculate inverse of |r|^3 real r3i = Constants::G * pow(r2, -1.5); // da = r / |r|^3 // dj = (v / |r|^3 - 3 * (r . v) * r / |r|^5 Vector da = r * r3i; Vector dj = (v - r * (3 * dot(r, v) / r2)) * r3i; // Calculate new acceleration and jerk p[i].acc += da * p[j].mass; p[i].jerk += dj * p[j].mass; p[j].acc -= da * p[i].mass; p[j].jerk -= dj * p[i].mass; // Collision estimation // Metric 1) tau = |r|^2 / |a(j) - a(i)| // Metric 2) tau = |r|^4 / |v|^4 real mij = p[i].mass + p[j].mass; real tau_est_q1 = r2 / (lengthsq(da) * mij * mij); real tau_est_q2 = (r2*r2) / (v2*v2); if (tau_est_q1 < tau_q) tau_q = tau_est_q1; if (tau_est_q2 < tau_q) tau_q = tau_est_q2; } } return sqrt(sqrt(tau_q)); }

    Read the article

  • Getting sign of an integer in Assembly

    - by Sagekilla
    Hi all, I'm writing some assembly for a project using MASM (32-bit), and I was wondering what would be the easiest way to do this: int delta = A - B; int value = floor((delta + sign(delta)) / 2); Which is basically the following mapping: For 1 < A < 9, and B = 5: A = [1, 2] -> -2 A = [3, 4] -> -1 A = [5] -> 0 A = [6, 7] -> +1 A = [8, 9] -> +1 Any help is much appreciated!

    Read the article

  • Efficiency of manually written loops vs operator overloads (C++)

    - by Sagekilla
    Hi all, in the program I'm working on I have 3-element arrays, which I use as mathematical vectors for all intents and purposes. Through the course of writing my code, I was tempted to just roll my own Vector class with simple +, -, *, /, etc overloads so I can simplify statements like: for (int i = 0; i < 3; i++) r[i] = r1[i] - r2[i]; // becomes: r = r1 - r2; Which should be more or less identical in generated code. But when it comes to more complicated things, could this really impact my performance heavily? One example that I have in my code is this: Manually written version: for (int j = 0; j < 3; j++) { p.vel[j] = p.oldVel[j] + (p.oldAcc[j] + p.acc[j]) * dt2 + (p.oldJerk[j] - p.jerk[j]) * dt12; p.pos[j] = p.oldPos[j] + (p.oldVel[j] + p.vel[j]) * dt2 + (p.oldAcc[j] - p.acc[j]) * dt12; } Using a Vector class with operator overloads: p.vel = p.oldVel + (p.oldAcc + p.acc) * dt2 + (p.oldJerk - p.jerk) * dt12; p.pos = p.oldPos + (p.oldVel + p.vel) * dt2 + (p.oldAcc - p.acc) * dt12; I am compiling my code for maximum possible speed, as it's extremely important that this code runs quickly and calculates accurately. So will me relying on my Vector's for these sorts of things really affect me? For those curious, this is part of some numerical integration code which is not trivial to run in my program. Any insight would be appreciated, as would any idioms or tricks I'm unaware of.

    Read the article

  • Take positive square root in Mathematica

    - by Sagekilla
    Hi all, I'm currently doing some normalization along the lines of: J = Integrate[Psi[x, 0]^2, {x, 0, a}] sol = Solve[J == 1, A] A /. sol For this type of normalization, the negative square root is extraneous. My results are: In[49]:= J = Integrate[Psi[x, 0]^2, {x, 0, a}] Out[49]= 2 A^2 In[68]:= sol = Solve[J == 1, A] Out[68]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}} Even if I try giving it an Assuming[...] or Simplify[...], it still gives me the same results: In[69]:= sol = Assuming[A > 0, Solve[J == 1, A]] Out[69]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}} In[70]:= sol = FullSimplify[Solve[J == 1, A], A > 0] Out[70]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}} Can anyone tell me what I'm doing wrong here? I'd much appreciate it! If it helps any, I'm running Mathematica 7 on Windows 7 64-bit.

    Read the article

  • Rounding a positive number to a power of another number

    - by Sagekilla
    I'm trying to round a number to the next smallest power of another number. The number I'm trying to round is always positive. I'm not particular on which direction it rounds, but I prefer downwards if possible. I would like to be able to round towards arbitrary bases, but the ones I'm most concerned with at the moment is base 2 and fractional powers of 2 like 2^(1/2), 2^(1/4), and so forth. Here's my current algorithm for base 2. The log2 I multiply by is actually the inverse of log2: double roundBaseTwo(double x) { return 1.0 / (1 << (int)((log(x) * log2)) } Any help would be appreciated!

    Read the article

  • Bouncing a ball off a surface

    - by Sagekilla
    Hi all, I'm currently in the middle of writing a game like Breakout, and I was wondering how I could properly bounce a ball off a surface. I went with the naive way of rotating the velocity by 180 degrees, which was: [vx, vy] -> [-vy, vx] Which (unsurprisingly) didn't work so well. If I know the position and veocity of the ball, as well as the point the ball would hit (but is going to instead bounce off of) how can I bounce it off that point? I don't need any language specific code. If anyone could provide a small, mathematical formula on how to properly do this that would work fine for me. I also need this to work with integer positions and velocity (I can't use floating point anywhere). Thanks!

    Read the article

  • Creating multiple instances of a generic database

    - by sagekilla
    Hi all, currently I'm trying to have a setup where a generic database is distributed to students. They would develop an application using this database (Say a shopping cart application), submit their project onto our server, and then it would be graded automatically. These databases are being run in Microsoft SQL Server 2005. We're using user instances to instantiate each database, and multiple requests could be serviced at once. But, the problem is when more than one student submitted a project to be graded, the first database to be instantiated would be the only one and would overwrite all other copies that were currently open. So if stu1 modified his database and stu2 and stu3 had their projects being graded concurrently, at the end of the grading stu1, stu2, and stu3 would have identical DB's at the end. Is there any way I can have multiple independent copies of a generic database, each of which I can load concurrently and modify without having any changes made to any one affecting the others? I did a little reading, and thought it might be possible to do something along the lines of: Student submits project Attach the database with unique db name (specified by student) Do all necessary operations Detach the database I'm unsure if this would fix our problem or be possible, so any help would be much appreciated!

    Read the article

1