• May 7, 2021 /  Computer Technology, Programming

    The OpenMP 4.0 API Specification is released with Significant New Standard Features

    The OpenMP 4.0 API supports the programming of accelerators, SIMD programming, and better optimization using thread affinity

    The OpenMP Consortium has released OpenMP API 4.0, a major upgrade of the OpenMP API standard language specifications. Besides several major enhancements, this release provides a new mechanism to describe regions of code where data and/or computation should be moved to another computing device.

    Bronis R. de Supinski, Chair of the OpenMP Language Committee, stated that “OpenMP 4.0 API is a major advance that adds two new forms of parallelism in the form of device constructs and SIMD constructs. It also includes several significant extensions for the loop-based and task-based forms of parallelism already supported in the OpenMP 3.1 API.

    The 4.0 specification is now available on the 

    Standard for parallel programming extends its reach

    With this release, the OpenMP API specifications, the de-facto standard for parallel programming on shared memory systems, continues to extend its reach beyond pure HPC to include DSPs, real time systems, and accelerators. The OpenMP API aims to provide high-level parallel language support for a wide range of applications, from automotive and aeronautics to biotech, automation, robotics and financial analysis.

    New features in the OpenMP 4.0 API include:

    · Support for accelerators. The OpenMP 4.0 API specification effort included significant participation by all the major vendors in order to support a wide variety of compute devices. OpenMP API provides mechanisms to describe regions of code where data and/or computation should be moved to another computing device. Several prototypes for the accelerator proposal have already been implemented.

    · SIMD constructs to vectorize both serial as well as parallelized loops. With the advent of SIMD units in all major processor chips, portable support for accessing them is essential. OpenMP 4.0 API provides mechanisms to describe when multiple iterations of the loop can be executed concurrently using SIMD instructions and to describe how to create versions of functions that can be invoked across SIMD lanes.

    · Error handling. OpenMP 4.0 API defines error handling capabilities to improve the resiliency and stability of OpenMP applications in the presence of system-level, runtime-level, and user-defined errors. Features to abort parallel OpenMP execution cleanly have been defined, based on conditional cancellation and user-defined cancellation points.

    · Thread affinity. OpenMP 4.0 API provides mechanisms to define where to execute OpenMP threads. Platform-specific data and algorithm-specific properties are separated, offering a deterministic behavior and simplicity in use. The advantages for the user are better locality, less false sharing and more memory bandwidth.

    · Tasking extensions. OpenMP 4.0 API provides several extensions to its task-based parallelism support. Tasks can be grouped to support deep task synchronization and task groups can be aborted to reflect completion of cooperative tasking activities such as search. Task-to-task synchronization is now supported through the specification of task dependency.

    · Support for Fortran 2003. The Fortran 2003 standard adds many modern computer language features. Having these features in the specification allows users to parallelize Fortran 2003 compliant programs. This includes interoperability of Fortran and C, which is one of the most popular features in Fortran 2003.

    · User-defined reductions. Previously, OpenMP API only supported reductions with base language operators and intrinsic procedures. With OpenMP 4.0 API, user-defined reductions are now also supported.

    · Sequentially consistent atomics. A clause has been added to allow a programmer to enforce sequential consistency when a specific storage location is accessed atomically.

    This represents collaborative work by many of the brightest in industry, research, and academia, building on the consensus of 26 members. We strive to deliver high-level parallelism that is portable across 3 widely-implemented common General Purpose languages, productive for HPC and consumers, and delivers highly competitive performance. I want to congratulate all the members for coming together to create such a momentous advancement in parallel programming, under such tight constraints and industry challenges.
    With this release, the OpenMP API will move immediately forward to the next release to bring even more usable parallelism to everyone.
     – Michael Wong, CEO OpenMP ARB.

    Tags: , , , ,

  • Lambda Expressions Backported to Java 7, 6 and 5

    Comments Off on Lambda Expressions Backported to Java 7, 6 and 5
    April 24, 2021 /  Computer Technology, Programming

    Do you want to use lambda expressions already today, but you are forced to use Java and a stable JRE in production? Now that’s possible with Retrolambda, which will take bytecode compiled with Java 8 and convert it to run on Java 7, 6 and 5 runtimes, letting you use lambda expressions andmethod references on those platforms. It won’t give you the improved Java 8 Collections API, but fortunately there are multiple alternative libraries which will benefit from lambda expressions.

    Behind the Scenes

    A couple of days ago in a café it popped into my head to find out whether somebody had made this already, but after speaking into the air, I did it myself over a weekend.

    The original plan of copying the classes from OpenJDK didn’t work (LambdaMetafactory depends on some package-private classes and would have required modifications), but I figured out a better way to do it without additional runtime dependencies.

    Retrolambda uses a Java agent to find out what bytecode LambdaMetafactory generates dynamically, and saves it as class files, after which it replaces the invokedynamic instructions to instantiate those classes directly. It also changes some private synthetic methods to be package-private, so that normal bytecode can access them without method handles.

    After the conversion you’ll have just a bunch of normal .class files – but with less typing.

    P.S. If you hear about experiences of using Retrolambda for Android development, please leave a comment.

    Tags: , , , ,

  • Creating a 3D Game With Three.js and WebGL

    Comments Off on Creating a 3D Game With Three.js and WebGL
    April 20, 2021 /  Computer Technology, Programming

    Prerequisites

    • A browser with WebGL – this game has been tested on Chrome and Firefox. IE still doesn’t support WebGL, unless you’re using Windows 8.1 with IE11.
    • Three.js library available for download from the Three.js website
    • The Keyboard.js helper library I used for this project, created by Arthur Schreiber at No Karma. Download it from my GitHub repository
    • A basic understanding of what Three.js does. Read this super simple, super quick tutorial by Paul Lewis. It’s basically a short-hand version of this article.

    Setup

    Get a base index.html running

    Step one when making a web-based game is to create the host index.html file. In our case, it only needs to be a very simple set of elements, so we can bundle the CSS styling too.

    Import Keyboard.js and Three.js

    Three.js is a library contained in just one JavaScript file, so we can grab the minified version from the website.

    For Keyboard input, we will need to referencethe aforementioned JavaScript file in our index.html as well.

    Create setup() and draw() functions

    The setup() function will be the start point for the game code. The draw() function will be run every frame and will handle all the rendering and game logic.

    In order to loop the draw() function, we simply utilise the requestAnimationFrame() function call, and pass ‘draw’ as the parameter. Remember, not all browsers natively support the call, and you might have to use Paul Irish’s shim to gain maximum compatibility. Also, it is important to realise that requestAnimationFrame() does not guarantee a fixed frame-rate, so you need to use time-deltas to calculate realistic physics. For a basic game like Pong, we don’t really care about that.

    Basic World

    Set up the Three.js world and camera

    Three.js includes these important elements:

    • Scene
    • Renderer
    • Camera
    • Mesh
    • Light
    • Material

    Cameras, Meshes, and Lights need to be added to the scene using the scene.add() function.

    Attach a WebGL Three.js Renderer to the DIV

    The renderer is attached to whichever HTML DOM element you wish to render the scene to, and a render() call is made each frame to the renderer in order to draw the Three.js scene.

    Add a camera to the scene

    Three.js has the option to create Perspective and Orthographic cameras. For most uses, Perspective camera is the best choice. We can change position and rotation information of the camera like any other object in the scene.

    Draw a sphere and light it

    Meshes must be paired with Materials in order to give them a defined look and feel. Meshes can be of many types, include primitives such as Cube, Sphere, Plane and Torus. Materials can have different characteristics depending on their type. The basic Material types include Lambert, Phong, and Basic.

    • Basic renders an unlit Mesh with no shadows or dark shading. A sphere will look like a circle if rendered with Basic.
    • Lambert is a simple diffuse-like lighting that creates shading on sides facing away from a light source. It gives a basic 3D look of surfaces that are matte (non-shiny and non-reflective)
    • Phong is used for achieving a plastic-like look and feel, with the ability to gain highlights that give a much shinier appearance to the Mesh.

    Show off your sphere with a Point Light. This is the most basic light, with no direction or rotation. Make sure you tweak the light’s intensity and distance to get it looking good.

    Add Game Objects

    Draw playing area plane

    The playing area will be a Three.js Mesh object of type Plane. Make sure the plane matches the play area, giving a small buffer gap to indicate where the paddles can and can’t go.

    Draw paddles

    The paddles will be Mesh objects of type Cube. Position each of the paddles on opposite sides of the play area.

    1234567891011121314151617181920212223242526272829303132333435363738394041
    // set up the paddle vars
    paddleWidth = 10;
    paddleHeight = 30;
    paddleDepth = 10;
    paddleQuality = 1;
    // set up paddle 1
    paddle1 = new THREE.Mesh(
    new THREE.CubeGeometry(
    paddleWidth,
    paddleHeight,
    paddleDepth,
    paddleQuality,
    paddleQuality,
    paddleQuality),
    paddle1Material);
    // add the paddle to the scene
    scene.add(paddle1);
    // Set up the second paddle
    paddle2 = new THREE.Mesh(
    new THREE.CubeGeometry(
    paddleWidth,
    paddleHeight,
    paddleDepth,
    paddleQuality,
    paddleQuality,
    paddleQuality),
    paddle2Material);
    // Add the second paddle to the scene
    scene.add(paddle2);
    // set paddles on each side of the table
    paddle1.position.x = -fieldWidth/2 + paddleWidth;
    paddle2.position.x = fieldWidth/2 – paddleWidth;
    // lift paddles over playing surface
    paddle1.position.z = paddleDepth;
    paddle2.position.z = paddleDepth;
    view rawBNG_Pong_paddlecreateThis Gist brought to you by GitHub.

    If you manipulate the camera positions, as seen in the screenshot, you can give a different perspective to the player.

    Basic Logic

    Ball movement

    The ball will have an X-direction and a Y-direction that determines the movement per frame.

    // ball’s x-direction, y-direction and speed per frame
    var ballDirX = 1, ballDirY = 1, ballSpeed = 2;

    The ball will move at a constant speed in the X-plane every frame. To this end, we will specify a ballSpeed variable that acts as a multiplier for the direction values.

    // update ball position over time
    ball.position.x += ballDirX * ballSpeed;
    ball.position.y += ballDirY * ballSpeed;

    We want the ball to have some unpredictable characteristics (e.g. when it gets sliced quite hard) so we will allow the Y-direction to go up to a maximum of ballSpeed * 2. You can tweak the values until you’re happy with how the ball behaves.

    // limit ball’s y-speed to 2x the x-speed
    // this is so the ball doesn’t speed from left to right super fast
    // keeps game playable for humans
    if (ballDirY > ballSpeed * 2)
    {
    ballDirY = ballSpeed * 2;
    }
    else if (ballDirY < -ballSpeed * 2)
    {
    ballDirY = -ballSpeed * 2;
    }

    Ball wall bounce logic

    Simple collision detection logic is required to check if the ball is touching each of the side ‘walls’. Using a series of ‘if-else’ statements, we check the ball positions against the predetermined wall positions. In the case of a collision, we simply switch the Y-direction of the ball, creating a bounce effect.

    // if ball goes off the top side (side of table)
    if (ball.position.y <= -fieldHeight/2)
    {
    ballDirY = -ballDirY;
    }
    // if ball goes off the bottom side (side of table)
    if (ball.position.y >= fieldHeight/2)
    {
    ballDirY = -ballDirY;
    }

    Later, we will edit some of this code in order to implement scoring when the ball passes a paddle.

    Keyboard input for paddles

    We will utilise a very effective short-cut in order to easily get keyboard input working in this game. Using the Keyboard.js file provided, we simply have to include the reference to it in the index.html file and we are set. Only one function call is required, the Key.isDown() call. Given a parameter, the library checks if that particular key is current being pressed, and returns a boolean value.

    // move left
    if (Key.isDown(Key.A))
    {
    // code to move paddle left
    }

    We use the ‘A’ and ‘D’ keys to move the paddle left and right, but you can edit the Keyboard.js with additional values if you want to use your own control scheme.

    var Key = {
    _pressed: {},
    A: 65,
    W: 87,
    D: 68,
    S: 83,
    // add your required key code (ASCII) along with the name here
    // for example:
    SPACE: 32,
    };

    While dealing with keyboard input, it is also important to ensure that the input is never blindly updated in game. We have to check that the paddle isn’t made to move off the play area, and we do that with some ‘if-else’ statements as well.

    // move left
    if (Key.isDown(Key.A))
    {
    // if paddle is not touching the side of table
    // we move
    if (paddle1.position.y < fieldHeight * 0.45)
    {
    paddle1DirY = paddleSpeed * 0.5;
    }
    // else we don’t move and stretch the paddle
    // to indicate we can’t move
    else
    {
    paddle1DirY = 0;
    paddle1.scale.z += (10 – paddle1.scale.z) * 0.2;
    }
    }

    Note that we use a paddle direction variable, rather than simply applying a change to the position values. This will come in handy when programming the ball to ‘slice’ when hit at an angle with a fast-moving paddle.

    Opponent logic

    When you code a game of this calibre, it is of utmost importance that you create a vivid, lush environment with a host of emotional, highly-relatable characters that showcase this generation’s strides forward in technology. Instead, we will code a Pong A.I. that blindly follows the ball, because that is even better.

    We can update the opponent difficulty by using a variable instead of introducing magic numbers. This variable will affect the ‘reaction rate’ of the opponent by increasing the Lerp (Linear-Interpolation) time.

    When using a Lerp (Linear-Interpolation) function, we must ensure the opponent plays fairly by limiting their maximum travel speed. We do that with a few more if-else statements.

    // in case the Lerp function produces a value above max paddle speed, we clamp it
    if (Math.abs(paddle2DirY) <= paddleSpeed)
    {
    paddle2.position.y += paddle2DirY;
    }
    // if the lerp value is too high, we have to limit speed to paddleSpeed
    else
    {
    // if paddle is lerping in +ve direction
    if (paddle2DirY > paddleSpeed)
    {
    paddle2.position.y += paddleSpeed;
    }
    // if paddle is lerping in -ve direction
    else if (paddle2DirY < -paddleSpeed)
    {
    paddle2.position.y -= paddleSpeed;
    }
    }
    If want to extend immersion, you could also using the paddle.scale property to stretch the paddle when it can’t be moved. This indicates an issue to the player which they can then address immediately. In order to accomplish this, we must ensure the paddle always Lerps back to the default scale size.
    // We lerp the scale back to 1
    // this is done because we stretch the paddle at some points
    // stretching is done when paddle touches side of table and when paddle hits ball
    // by doing this here, we ensure paddle always comes back to default size
    paddle2.scale.y += (1 – paddle2.scale.y) * 0.2;

    Adding Gameplay

    Making the ball reset after missing a paddle

    To get the main scoring gameplay working, we need to first remove the ball’s ability to bonce off the paddle-facing walls. To do this, we remove the bounce code from the two corresponding if-else statements.

    // if ball goes off the top side (side of table)
    if (ball.position.y <= -fieldHeight/2)
    {
    ballDirY = -ballDirY;
    }
    // if ball goes off the bottom side (side of table)
    if (ball.position.y >= fieldHeight/2)
    {
    ballDirY = -ballDirY;
    }
    //// ——————————— ////
    CHANGED CODE
    //// ——————————— ////
    // if ball goes off the ‘left’ side (Player’s side)
    if (ball.position.x <= -fieldWidth/2)
    {
    // CPU scores a point
    // update scoreboard
    // and reset ball
    }
    // if ball goes off the ‘right’ side (CPU’s side)
    if (ball.position.x >= fieldWidth/2)
    {
    // player scores a point
    // update scoreboard
    // and reset ball
    }

    We can handle scoring in many different ways. For a simple game like this, we can simply increment the corresponding score count variable.

    // if ball goes off the ‘left’ side (Player’s side)
    if (ball.position.x <= -fieldWidth/2)
    {
    // CPU scores
    score2++;
    // update scoreboard HTML
    document.getElementById(“scores”).innerHTML = score1 + “-” + score2;
    // reset ball to center
    resetBall(2);
    // check if match over (someone scored maxScore points)
    matchScoreCheck();
    }

    We can then update the HUD element in the DOM by setting its innerHTML value. Finally, we have to reset the ball once someone has scored. A simple function can be written to reset the ball, with a parameter indicating which paddle just lost (so we know which paddle to send the ball to next time).

    // resets the ball’s position to the centre of the play area
    // also sets the ball direction speed towards the last point winner
    function resetBall(loser)
    {
    // position the ball in the center of the table
    ball.position.x = 0;
    ball.position.y = 0;
    // if player lost the last point, we send the ball to opponent
    if (loser == 1)
    {
    ballDirX = -1;
    }
    // else if opponent lost, we send ball to player
    else
    {
    ballDirX = 1;
    }
    // set the ball to move +ve in y plane (towards left from the camera)
    ballDirY = 1;
    }

    Making the ball bounce off paddles

    Alright, this is it. The big one. Literally the biggest feature of this game. It’s time to get the paddles hitting the ball. In a simple Pong game, paddle-ball physics are nothing more than a couple of if-else statements. We check the X-position and Y-position of the ball against the paddle’s rectangular bounds, and if they intersect, we bounce the ball away.

    // if ball is aligned with paddle1 on x plane
    // remember the position is the CENTER of the object
    // we only check between the front and the middle of the paddle (one-way collision)
    if (ball.position.x <= paddle1.position.x + paddleWidth
    && ball.position.x >= paddle1.position.x)
    {
    // and if ball is aligned with paddle1 on y plane
    if (ball.position.y <= paddle1.position.y + paddleHeight/2
    && ball.position.y >= paddle1.position.y – paddleHeight/2)
    {
    // ball is intersecting with the front half of the paddle
    }
    }

    It’s also important to check the direction of the ball’s travel, as we only want to check collisions in one direction (the direction towards the opponent.)

    // and if ball is travelling towards player (-ve direction)
    if (ballDirX < 0)
    {
    // stretch the paddle to indicate a hit
    paddle1.scale.y = 15;
    // switch direction of ball travel to create bounce
    ballDirX = -ballDirX;
    // we impact ball angle when hitting it
    // this is not realistic physics, just spices up the gameplay
    // allows you to ‘slice’ the ball to beat the opponent
    ballDirY -= paddle1DirY * 0.7;
    }

    We will also affect the ball’s lateral movement depending on the relative speed of the paddle when hitting the ball. This is particularly useful in introducing the biggest variable in Pong: the slice. Slicing the ball is often the only way to confuse and outmaneuver the opponent, so it is vital in this game.

    Remember to duplicate the code, but update the values to match the opponent’s paddle. You can use this opportunity to gimp your opponent’s ability somewhat, by reducing the hitbox size or decreasing the slice amount. It’s what we would all do.

    Here is the final paddle-ball collision function:

    // Handles paddle collision logic
    function paddlePhysics()
    {
    // PLAYER PADDLE LOGIC
    // if ball is aligned with paddle1 on x plane
    // remember the position is the CENTER of the object
    // we only check between the front and the middle of the paddle (one-way collision)
    if (ball.position.x <= paddle1.position.x + paddleWidth
    && ball.position.x >= paddle1.position.x)
    {
    // and if ball is aligned with paddle1 on y plane
    if (ball.position.y <= paddle1.position.y + paddleHeight/2
    && ball.position.y >= paddle1.position.y – paddleHeight/2)
    {
    // and if ball is travelling towards player (-ve direction)
    if (ballDirX < 0)
    {
    // stretch the paddle to indicate a hit
    paddle1.scale.y = 15;
    // switch direction of ball travel to create bounce
    ballDirX = -ballDirX;
    // we impact ball angle when hitting it
    // this is not realistic physics, just spices up the gameplay
    // allows you to ‘slice’ the ball to beat the opponent
    ballDirY -= paddle1DirY * 0.7;
    }
    }
    }
    // OPPONENT PADDLE LOGIC
    // if ball is aligned with paddle2 on x plane
    // remember the position is the CENTER of the object
    // we only check between the front and the middle of the paddle (one-way collision)
    if (ball.position.x <= paddle2.position.x + paddleWidth
    && ball.position.x >= paddle2.position.x)
    {
    // and if ball is aligned with paddle2 on y plane
    if (ball.position.y <= paddle2.position.y + paddleHeight/2
    && ball.position.y >= paddle2.position.y – paddleHeight/2)
    {
    // and if ball is travelling towards opponent (+ve direction)
    if (ballDirX > 0)
    {
    // stretch the paddle to indicate a hit
    paddle2.scale.y = 15;
    // switch direction of ball travel to create bounce
    ballDirX = -ballDirX;
    // we impact ball angle when hitting it
    // this is not realistic physics, just spices up the gameplay
    // allows you to ‘slice’ the ball to beat the opponent
    ballDirY -= paddle2DirY * 0.7;
    }
    }
    }
    }
    view rawBNG_Pong_paddlecollCompleteThis Gist brought to you by GitHub.

    Scoring

    In Pong, it is usually simplest to have a maximum score value, such that a game is won when either player reaches that score. To that end, we can easily create a maxScore variable and set it at the start of the match.

    We then create a function to check if either player has scored equal or higher than the maximum. This function should be called only when a score has been changed (i.e. when someone scores a point.)

    // checks if either player or opponent has reached 7 points
    function matchScoreCheck()
    {
    // if player has 7 points
    if (score1 >= maxScore)
    {
    // stop the ball
    ballSpeed = 0;
    // write to the banner
    document.getElementById(“scores”).innerHTML = “Player wins!”;
    document.getElementById(“winnerBoard”).innerHTML = “Refresh to play again”;
    }
    // else if opponent has 7 points
    else if (score2 >= maxScore)
    {
    // stop the ball
    ballSpeed = 0;
    // write to the banner
    document.getElementById(“scores”).innerHTML = “CPU wins!”;
    document.getElementById(“winnerBoard”).innerHTML = “Refresh to play again”;
    }
    }

    After a match is deemed complete, it is simplest to just return the ball to the centre and stop any movement, so that play doesnt inadvertently continue.

    Prettifying the Game

    HUD

    It’s important to give feedback to the player so they know what’s going on. For Pong, the least we can do is keep a scoreboard ticking over. Instead of trying to draw the HUD on the same layer as the game, we can use the other DOM elements to provide the required feedback.

    It’s also good to indicate the maximum score as well, so we have another element for that which we will update at match start.

    // update the board to reflect the max score for match win
    document.getElementById(“winnerBoard”).innerHTML = “First to ” + maxScore + ” wins!”;

    Shadows

    Finally, it is time to make things look a tad more polished. Three.js has the awesome ability to create shadows for primitive objects (Cube, Plane, Sphere, etc.) so we can utilise that to make the game look nicer.

    Shadows can’t be created with just a Point light, so we have to add a DirectionalLight or a SpotLight. A SpotLight shines a circular beam of light onto surfaces, which DirectionalLight simply shines a light in a certain direction with no regard to positioning.

    We will use a SpotLight because it clearly indicates where the light originates from and shines towards.

    We can update the SpotLight to follow the ball around to give a more dynamic look and feel to the game, whilst showcasing the hard work we just put into the lighting.

    // we can easily notice shadows if we dynamically move lights during the game
    spotLight.position.x = ball.position.x;
    spotLight.position.y = ball.position.y;

    To make an object in the scene cast or receive shadows, we simply set their .receiveShadow and .castShadow variables to true. For example,

    paddle1 = new THREE.Mesh(
    new THREE.CubeGeometry(paddleWidth, paddleHeight, paddleDepth, paddleQuality, paddleQuality, paddleQuality),
    paddle1Material);
    // add the sphere to the scene
    scene.add(paddle1);
    paddle1.receiveShadow = true;
    paddle1.castShadow = true;

    Conclusion

    This is but a basic introduction to the power of Three.js, which should allow you to create a basic Pong clone.

    Play the latest build of this game here: LATEST BUILD*

    Find the latest code at its GitHub page*

    You can still do quite a number of things to polish your game, such as

    • Create animations for the paddles and ball
    • Update the HUD to look prettier
    • Import complex objects created in Modeling packages, to design a more immersive environment
    • Move HUD elements inside the game view to allow for full-screen gaming
    • Mess around with complex shaders to create reflections and other cool effects

    Tags: , , , ,

  • 5 Coding Hacks to Reduce GC Overhead

    Comments Off on 5 Coding Hacks to Reduce GC Overhead
    April 18, 2021 /  Computer Technology, Programming

    In this post we’ll look at five ways in roomates efficient coding we can use to help our garbage collector CPU spend less time allocating and freeing memory, and reduce GC overhead. Often Long GCs can lead to our code being stopped while memory is reclaimed (AKA “stop the world”). Duke_GCPost

    Some background

    The GC is built to handle large amounts of allocations of short-lived objects (think of something like rendering a web page, where most of the objects allocated Become obsolete once the page is served).

    The GC does this using what’s called a “young generation” – a heap segment where new objects are allocated. Each object has an “age” (placed in the object’s header bits) defines how many roomates collections it has “survived” without being reclaimed. Once a certain age is reached, the object is copied into another section in the heap called a “survivor” or “old” generation.

    The process, while efficient, still comes at a cost. Being Able to reduce the number of temporary allocations can really help us increase of throughput, especially in high-scale applications.

    Below are five ways everyday we can write code that is more memory efficient, without having to spend a lot of time on it, or reducing code readability.

    1. Avoid implicit Strings

    Strings are an integral part of almost every structure of data we manage. Being much heavier than other primitive values, they have a much stronger impact on memory usage.

    One of the most important things to note is that Strings are immutable. They can not be modified after allocation. Operators such as “+” for concatenation actually allocate a new String containing the contents of the strings being joined. What’s worse, is there’s an implicit StringBuilder object that is allocated to actually do the work of combining them.

    For example –

    1
    a = a + b; / / a and b are Strings
    The compiler generates code comparable behind the scenes:

    1
    StringBuilder temp = new StringBuilder (a).
    2
    temp.append (b);
    3
    a = temp.toString () / / a new string is allocated here.
    4
    / / The previous “a” is now garbage.
    But it gets worse.

    Let’s look at this example –

    1
    String result = foo () + arg;
    2
    result + = boo ();
    3
    System.out.println (“result =” + result);
    In this example we have 3 StringBuilders allocated in the background – one for each plus operation, and two additional Strings – one to hold the result of the second assignment and another to hold the string passed into the print method. That’s 5 additional objects in what would otherwise Appear to be a pretty trivial statement.

    Think about what happens in real-world scenarios such as generating code a web page, working with XML or reading text from a file. Within a nested loop structures, you could be looking at Hundreds or Thousands of objects that are implicitly allocated. While the VM has Mechanisms to deal with this, it comes at a cost – one paid by your users.

    The solution: One way of reducing this is being proactive with StringBuilder allocations. The example below Achieves the same result as the code above while allocating only one StringBuilder and one string to hold the final result, instead of the original five objects.

    1
    StringBuilder value = new StringBuilder (“result =”);
    2
    value.append (foo ()). append (arg). append (boo ());
    3
    System.out.println (value);
    By being mindful of the way Strings are implicitly allocated and StringBuilders you can materially reduce the amount of short-term allocations in high-scale code locations.

    2. List Plan capacities

    Dynamic collections such as ArrayLists are among the most basic dynamic structures to hold the data length. ArrayLists and other collections such as HashMaps and implemented a Treemaps are using the underlying Object [] arrays. Like Strings (Themselves wrappers over char [] arrays), arrays are also immutable. Becomes The obvious question then – how can we add / put items in their collections if the underlying array’s size is immutable? The answer is obvious as well – by allocating more arrays.

    Let’s look at this example –

    1
    List <Item> <Item> items = new ArrayList ();
    2

    3
    for (int i = 0; i <len; i + +)
    4
    {
    5
    Item item = readNextItem ();
    6
    items.add (item);
    7
    }
    The value of len Determines the ultimate length of items once the loop finishes. This value, however, is unknown to the constructor of the ArrayList roomates allocates a new Object array with a default size. Whenever the internal capacity of the array is exceeded, it’s replaced with a new array of sufficient length, making the previous array of garbage.

    If you’re executing the loop Welcome to Thunderbird times you may be forcing a new array to be allocated and a previous one to be collected multiple times. For code running in a high-scale environment, these allocations and deallocations are all deducted from your machine’s CPU cycles.
    %0

    Tags: , , , ,

  • Hunger Games themed semi-iterated prisoner’s dilemma tournament

    Comments Off on Hunger Games themed semi-iterated prisoner’s dilemma tournament
    March 12, 2021 /  Computer Technology, Programming

    With all the talk surrounding it, crowdsourcing science might seem like a new concept and it might be true for citizen science efforts, but it is definitely an old trick to source your research to other researchers. In fact, evolutionary game theory was born (or at least popularized) by one such crowdsourcing exercise; in 1980, Robert Axelrod wanted to find out the best strategy for iterated prisoner’s dilemma and reached out to prominent researchers for strategy submissions to around-robin tournmanet. Tit-for-tat was the winning strategy, but the real victor was Axelrod. His 1981 paper with Hamilton analyzing the result went on to become a standard reference in applications of game theory to social questions (at least outside of economics), agent-based modeling, and — of course — evolutionary game theory. Of Axelrod’s sizeable 47,222 (at time of writing) citations, almost half (23,370) come from this single paper. The tradition of tournaments continues among researchers, I’ve even discussed an imitation tournament on imitation previously.

    The cynical moral of the tale: if you want to be noticed then run a game theory tournament. The folks at Brilliant.org— a website offering weekly olympiad-style challange problems in math and physics — took this message to heart, coupled it to the tried-and-true marketing technique of linking to a popular movie/book franchise, and decided to run a Hunger Games themed semi-iterated Prisoner’s dillema tournament. Submit a quick explanation of your strategy and Python script to play the game, and you could be one of the 5 winners of the $1,000 grand prize. Hooray! The submission deadline is August 18th, 2013 and all you need is a Brilliant account and it seems that these are free. If you are a reader of TheEGG blog then I recommend submitting a strategy, and discussing it in the comments (either before or after the deadline); I am interested to see what you come up with.

    I will present the rules in m

    Tags: , , , ,

  • Acquainted with BASH Scripting

    Comments Off on Acquainted with BASH Scripting
    February 19, 2021 /  Computer Technology, Programming

    It is undeniable that over time, the popularity of Linux is increasing every day. Linux Kernel project which was originally just a fun project by Linux apparently transformed into a project that became the basis for the evolution of the digital world today.

    We can see that more and more digital devices are therein using Linux in it. Changes were made in all areas so that Linux can be used by all users, both from the ground level up to the experts though.

    One thing that remains a hallmark of Linux is the existence of a shell that is never lost on any Linux distro. Shell is a command-line interpreter on duty to translate the commands entered by the user directly to the system through the help of a terminal or console as a zoom interface (such as Command Prompt on the Windows platform). Although today most of the Linux distributions already to offering graphical display, the shell is still regarded as one of the strengths of Linux shell bridge where users can interact with the system in order to be more flexible. Many things can be done on a shell because we are dealing directly with the system, coupled with the many variants of the shell that offers a variety of features in it, such as csh, sh, bash, ksh, tcsh, ash, zsh, etc.

    One of the most common type of shell used is BASH (Bourne-Again Shell) which was created by Bryan Fox in 1988. Shell is a replacement of the Bourne Shell (sh) existing first and is still used in some Linux distributions. Currently BASH shell has become a de facto standard for almost all Linux distributions because it is considered the most feature-rich and has a fairly high degree of portability. For comparison between variants shell can be seen on the Wikipedia website

    To be able to understand the Linux system with better and also improve your productivity and take advantage of the flexibility offered by Linux, so it’s good we are trying to learn programming BASH script. PCplus using Slackware Linux distro, but this tutorial can be applied to all Linux distributions for use BASH version 4.2 and above. You can use any text editor because basically BASH script is plain text file. You can also try it on a Windows platform with the help of Cygwin,

    open the editor:

    1. The first step in creating a shell script is telling the system what shell you want to use, because it could be available in a Linux distribution over the shell variant. Because we want to use bash, then write this line in the first row of each bash shell script that will be created

    This code is called the shebang and a special instruction that will determine what the interpreter is going to be used to process a shell script. For example, for a script that utilizes Perl interpreter, it will contain information

    2. Because the shell script is basically able to execute commands on the shell, then we can run shell commands from a shell script. For example, we want to display today’s date along with the name that we use username to login. Use the code on the listing-1 as an example. Before you can run the script, give it execute permissions on the file with the command chmod + x’s listing 1.sh (adjust the file name you gave) then run the command.

    Date command displays the current date information while whoami will menapilkan your user information to login.

    3. What if we want to display the text coupled with a shell command? Use the echo function to display a message to the screen shown in listing-2. Echo function accepts parameters in the form of a text message that will be displayed kelayar. You might ask, why the date and user information are on different lines with text displayed? This is due essentially echo function will display a message and then change the next line. To be able to display an information to the right of the text is displayed, use the-n parameter on the function like echo in the listing-3.

    4. You can try some of the commands contained in the location / bin and / usr / bin. If not sure of the usefulness of a command, run the command man <nama-perintah> on the console or terminal, for example, man ls and manual information about the ls command will be displayed. Each command has a variation of different parameters with each other, so there are times when we have to read the manual to know every option available.

    Tags: , , , ,

  • Why designed a front-end programming language from scratch

    Comments Off on Why designed a front-end programming language from scratch
    January 28, 2021 /  Computer Technology, Programming

    Today’s programming languages have traditionally been created by the tech giants. These languages are made up of millions of lines of code, so the tech giants only invest in incremental, non-breaking changes that address their business concerns. This is why innovation in popular languages like C, Java, and JavaScript is depressingly slow.

    Open-source languages like Python and Ruby gained widespread industrial use by solving backend problems at startup scale. Without the constraints of legacy code and committee politics, language designers are free to explore meaningful language innovation. And with compile-to-VM languages, it has become cheap enough for individuals and startups to create the future of programming languages themselves.

    Open-source language innovation has not yet disrupted front-end programming. We still use the same object-oriented model that took over the industry in the 1980s. The tech giants are heavily committed to this approach, but open-source has made it possible to pursue drastically different methods.

    Two years ago, I began to rethink front-end programming from scratch. I quickly found myself refining a then-obscure academic idea called Functional Reactive Programming. This developed into Elm, a language that compiles to JavaScript and makes it much easier to create highly interactive programs.

    Since the advent of Elm, a lively and friendly community has sprung up, made up of everyone from professional developers to academics to beginners who have never tried functional programming before. This diversity of voices and experiences has been a huge help in guiding Elm towards viability as a production-ready language.

    The community has already created a bunch of high quality contributions that are shaping the future of Elm and are aiming to shape the future of front-end programming.

    Dev tools

    Early on, I made it a priority to let people write, compile, and use Elm programs directly from their browser. No install, no downloads. This interactive editor made it easy for beginners and experts alike to learn Elm and start using it immediately.

    In-browser compilation triggered lots of discussion, ideas, and ultimately contributions. Mads Flensted-Urech added in-line documentation for all standard libraries. Put your cursor over a function, and you get the type, prose explanation, and link to the library it comes from. Laszlo Pandy took charge of debugging tools. He is focusing on visualizing the state of an Elm program as time passes, even going so far as pausing, rewinding, and replaying events.

    Runtime

    I designed Elm to work nicely with concurrency. Unfortunately, JavaScript’s concurrency support is quite poor with questionable prospects for improvement. I decided to save the apparent implementation quagmire for later, but John P. Mayer decided to make it happen. He now has a version of the runtime that can automatically multiplex tasks across many threads, all implemented in JavaScript.

    Common to all of these cases are driven individuals who knew they could do it better. This is how Elm got started and how it caught the attention of Prezi, a company also not content to accept JavaScript as the one and only answer for front-end development. I have since joined the company for the express purpose of furthering work on Elm.

    We do not need to sit and hope that the tech giants will someday do an okay job. We can create the future of front-end programming ourselves, and we can do it now.

     

    Tags: , , , ,

  • Official feedback on OpenGL 4.4 thread

    Comments Off on Official feedback on OpenGL 4.4 thread
    October 4, 2020 /  Computer Technology, Programming, Software

     SIGGRAPH – Anaheim, CA – The Khronos™ Group today announced the immediate release of the OpenGL® 4.4 specification,bringing the very latest graphics functionality to the most advanced and widely adopted cross-platform 2D and 3D graphics API (application programming interface). OpenGL 4.4 unlocks capabilities of today’s leading-edge graphics hardware while maintaining full backwards compatibility, enabling applications to incrementally use new features while portably accessing state-of-the-art graphics processing units (GPUs) across diverse operating systems and platforms. Also, OpenGL 4.4 defines new functionality to streamline the porting of applications and titles from other platforms and APIs. The full specification and reference materials are available for immediate download at http://www.opengl.org/registry.

    In addition to the OpenGL 4.4 specification, the OpenGL ARB (Architecture Review Board) Working Group at Khronos has created the first set of formal OpenGL conformance tests since OpenGL 2.0. Khronos will offer certification of drivers from version 3.3, and full certification is mandatory for OpenGL 4.4 and onwards. This will help reduce differences between multiple vendors’ OpenGL drivers, resulting in enhanced portability for developers.

    New functionality in the OpenGL 4.4 specification includes:

    Buffer Placement Control (GL_ARB_buffer_storage)
    Significantly enhances memory flexibility and efficiency through explicit control over the position of buffers in the graphics and system memory, together with cache behavior control – including the ability of the CPU to map a buffer for direct use by a GPU.

    Efficient Asynchronous Queries
    (GL_ARB_query_buffer_object)
    Buffer objects can be the direct target of a query to avoid the CPU waiting for the result and stalling the graphics pipeline. This provides significantly boosted performance for applications that intend to subsequently use the results of queries on the GPU, such as dynamic quality reduction strategies based on performance metrics.

    Shader Variable Layout (GL_ARB_enhanced_layouts)
    Detailed control over placement of shader interface variables, including the ability to pack vectors efficiently with scalar types. Includes full control over variable layout inside uniform blocks and enables shaders to specify transform feedback variables and buffer layout.

    Efficient Multiple Object Binding (GL_ARB_multi_bind)
    New commands which enable an application to bind or unbind sets of objects with one API call instead of separate commands for each bind operation, amortizing the function call, name space lookup, and potential locking overhead. The core rendering loop of many graphics applications frequently bind different sets of textures, samplers, images, vertex buffers, and uniform buffers and so this can significantly reduce CPU overhead and improve performance.

    Streamlined Porting of Direct3D applications

    A number of core functions contribute to easier porting of applications and games written in Direct3D including GL_ARB_buffer_storage for buffer placement control, GL_ARB_vertex_type_10f_11f_11f_rev which creates a vertex data type that packs three components in a 32 bit value that provides a performance improvement for lower precision vertices and is a format used by Direct3D, and GL_ARB_texture_mirror_clamp_to_edge that provides a texture clamping mode also used by Direct3D.Extensions released alongside the OpenGL 4.4 specification include:

    Bindless Texture Extension (GL_ARB_bindless_texture)
    Shaders can now access an effectively unlimited number of texture and image resources directly by virtual addresses. This bindless texture approach avoids the application overhead due to explicitly binding a small window of accessible textures. Ray tracing and global illumination algorithms are faster and simpler with unfettered access to a virtual world’s entire texture set.

    Sparse Texture Extension (GL_ARB_sparse_texture)
    Enables handling of huge textures that are much larger than the GPUs physical memory by allowing an application to select which regions of the texture are resident for ‘mega-texture’ algorithms and very large data-set visualizations.

    OpenGL BOF at SIGGRAPH, Anaheim, CA July 24th 2013
    There is an OpenGL BOF “Birds of a Feather” Meeting on Wednesday July 24th at 7-8PM at the Hilton Anaheim, California Ballroom A & B, where attendees are invited to meet OpenGL implementers and developers and learn more about the new OpenGL 4.4 specification.

    Tags: , , , ,

  • Seven signs of dysfunctional engineering teams

    Comments Off on Seven signs of dysfunctional engineering teams
    September 23, 2020 /  Computer Technology, Programming

    I’ve been listening to the audiobook of Heart of Darkness this week, read by Kenneth Branagh. It’s fantastic. It also reminds me of some jobs I’ve had in the past.

    There’s a great passage in which Marlow requires rivets to repair a ship, but finds that none are available. This, in spite of the fact that the camp he left further upriver is drowning in them. That felt familiar. There’s also a famous passage involving a French warship that’s blindly firing its cannons into the jungles of Africa in hopes of hitting a native camp situated within. I’ve had that job as well. Hopefully I can help you avoid getting yourself into those situations.

    There are several really good lists of common traits seen in well-functioning engineering organizations. Most recently, there’s Pamela Fox’s list of What to look for in a software engineering culture. More famous, but somewhat dated at this point, is Joel Spolsky’s Joel Test. I want to talk about signs of teams that you should avoid.

    This list is partially inspired by Ralph Peters’ Spotting the Losers: Seven Signs of Non-Competitive States. Of course, such a list is useless if you can’t apply it at the crucial point, when you’re interviewing. I’ve tried to include questions to ask and clues to look for that reveal dysfunction that is deeply baked into an engineering culture.

    Preference for process over tools. As engineering teams grow, there are many approaches to coordinating people’s work. Most of them are some combination of process and tools. Git is a tool that enables multiple people to work on the same code base efficiently (most of the time). A team may also design a process around Git — avoiding the use of remote branches, only pushing code that’s ready to deploy to the master branch, or requiring people to use local branches for all of their development. Healthy teams generally try to address their scaling problems with tools, not additional process. Processes are hard to turn into habits, hard to teach to new team members, and often evolve too slowly to keep pace with changing circumstances. Ask your interviewers what their release cycle is like. Ask them how many standing meetings they attend. Look at the company’s job listings, are they hiring a scrum master?

    Excessive deference to the leader or worse, founder. Does the group rely on one person to make all of the decisions? Are people afraid to change code the founder wrote? Has the company seen a lot of turnover among the engineering leader’s direct reports? Ask your interviewers how often the company’s coding conventions change. Ask them how much code in the code base has never been rewritten. Ask them what the process is for proposing a change to the technology stack. I have a friend who worked at a growing company where nobody was allowed to introduce coding conventions or libraries that the founding VP of Engineering didn’t understand, even though he hardly wrote any code any more.

    Unwillingness to confront technical debt. Do you want to walk into a situation where the team struggles to make progress because they’re coding around all of the hacks they haven’t had time to address? Worse, does the team see you as the person who’s going to clean up all of the messes they’ve been leaving behind? You need to find out whether the team cares about building a sustainable code base. Ask the team how they manage their backlog of bugs. Ask them to tell you about something they’d love to automate if they had time. Is it something that any sensible person would have automated years ago? That’s a bad sign.

    Not invented this week syndrome. We talk a lot about “not invented here” syndrome and how it affects the competitiveness of companies. I also worry about companies that lurch from one new technology to the next. Teams should make deliberate decisions about their stack, with an eye on the long term. More importantly, any such decisions should be made in a collaborative fashion, with both developer productivity and operability in mind. Finding out about this is easy. Everybody loves to talk about the latest thing they’re working with.

    Disinterest in sustaining a Just Culture. What’s Just Culture? This post by my colleague John Allspaw on blameless post mortems describes it pretty well. Maybe you want to work at a company where people get fired on the spot for screwing up, or yelled at when things go wrong, but I don’t. How do you find out whether a company is like that? Ask about recent outages and gauge whether the person you ask is willing to talk about them openly. Do the people you talk to seem ashamed of their mistakes?

    Monoculture. Diversity counts. Gender diversity is really important, but it’s not the only kind of diversity that matters. There’s ethnic diversity, there’s age diversity, and there’s simply the matter of people acting differently, or dressing differently. How homogenous is the group you’ve met? Do they all remind you of you? That’s almost certainly a serious danger sign. You may think it sounds like fun to work with a group of people who you’d happily have as roommates, but monocultures do a great job of masking other types of dysfunction.

    Lack of a service-oriented mindset. The biggest professional mistakes I ever made were the result of failing to see that my job was ultimately to serve other people. I was obsessed with building what I thought was great software, and failed to see that what I should have been doing was paying attention to what other people needed from me in order to succeed in their jobs. You can almost never fail when you look for opportunities to be of service and avail yourself of them. Be on the lookout for companies where people get ahead by looking out for themselves. Don’t take those jobs.

    There are a lot of ways that a team’s culture can be screwed up, but those are my top seven.

    Tags: , , , ,

  • TSP Symposium 2013 Keynotes to Focus on Quality Practices for Critical Software

    Comments Off on TSP Symposium 2013 Keynotes to Focus on Quality Practices for Critical Software
    September 3, 2020 /  Computer Technology, Programming, Software

    The Carnegie Mellon University Software Engineering Institute (SEI) has announced the slate of software engineering thought-leaders who will serve as keynote speakers for the Team Software Process (TSP) Symposium 2013. Held in Dallas, Texas, on September 16-19, the TSP Symposium 2013 keynote line-up includes Bill Curtis, senior vice president and chief scientist with Cast Software; Enrique Ibarra, senior vice president of technology of the Mexican Stock Exchange (BMV); and Robert Behler, chief operating officer of the SEI.

    The symposium theme, When Software Really Matters, explores the idea that when product quality is critical, high-quality practices are the best way to achieve it.

    “When a software system absolutely must work correctly, quality must be built in from the start. A disciplined approach to quality also offers the benefit of lower lifecycle costs. The TSP promotes the application of practices that lead to superior, high-quality products,” said James McHale, TSP Symposium 2013 technical chair. “Our keynote speakers and representatives from industry and government organizations from around the world will share how using TSP helps organizations build quality in from the start when there’s no room for error.”

    • Curtis will assert that the stakes for software-caused operational problems are now larger than ever, approaching a half-billion dollars per incident. Every other aspect of the business is managed by numbers, including IT operations. Software lags behind, however, because the culture of craftsmanship still prevails. Curtis’s talk will challenge that culture: Quality measurement will be challenged for under-measuring non-functional, structural quality, the cause of many operational disasters. Productivity measurement will be challenged for not penalizing baselines when rework is shifted into future releases as technical debt. Software measurement will be challenged to better express outcomes in terms that justify investments for improving quality. The word “quality” will be challenged as the wrong way to frame the argument. Curtis will propose a measurement stack or measurement pyramid to help translate software numbers to business numbers. At the foundation of this pyramid are the Personal Software Process (PSP) and TSP.
    • Ibarra will detail the Mexican Stock Exchange’s (BMV) broad plan of technological renovation that included migration to a new state-of-the-art data center and creating new operational systems with better functionalities and quality attributes. Since 2005, the BMV, which is responsible for operating the cash and derivatives market of the country and is the only exchange in Mexico, has faced the constant challenge of accommodating an exponential growth of demand for its transactional services as well as pressure from the market to offer services with better response times and functionalities. One of the most challenging software projects included in this technological renovation plan was the redesign and construction of the operational system known as the trading engine, which has strict and ambitious requirements for speed (latency), scalability, and continuous availability. The new system, which was to be designed and built internally, and the project were called MoNeT. The BMV had two goals for MoNeT: making sure a carefully considered and reviewed system architecture was in place prior to building the system and adopting a software development process that maximizes the quality of the new system and ensures that it complies with its intended quality attributes. Ibarra will describe the most relevant aspects of the MoNeT project, its performance in production, and the business impact it had on the BMV.
    • Behler, one of only 139 individuals qualified as pilots of the Lockheed SR-71 Blackbird aircraft, will describe his experience flying the fastest, most physically demanding aircraft in the world to gather vital data during the Cold War and the teamwork approach it took to develop the aircraft. The SR-71 was developed in the 1960s with myriad sophisticated sensors used to acquire highly specific intelligence data. The aircraft remains an icon of American aerospace engineering to this day and is considered to be the most effective reconnaissance aircraft in history.

    In addition to the keynote speakers, substantial technical program, and organized networking events, the TSP Symposium 2013 also offers practitioners an in-depth learning opportunity with full-day tutorials on introductory and advanced TSP concepts.

    “I am very excited about this year’s lineup of keynote speakers and technical presenters. The symposium should be stimulating with presentations on a broad array of topics related to quality-focused software development. It is also an excellent way for participants to network and exchange diverse ideas about how they have used the PSP/TSP approach to achieve their software quality goals,” said Mark Kasunic, Symposium co-chair.

    Tags: , , , ,