The Source for Java Technology Collaboration
User: Password:



Alexander Schunk's Blog

September 2007 Archives


LinAlg API: Stable release

Posted by alexanderschunk on September 29, 2007 at 12:29 PM | Permalink

LinAlg API: Stable release

A first stable release of LinAlg API is available. This release offers a few new features, some changes and also some demo apps.

New Features

I have added a tiny utility class called UtilsDegrees to Radians:

With these two methods its possible to convert angles from degree to radian. The following image shows a demo application i have written that does just that:

For a screenshot i refer you to the LinAlg API project homepage linalg.dev.java.net.

Complex class

The Complex class has undergone the most significant changes. Now the Complex class offers almost all features you need to work with Complex numbers. Below is a list of new features:

  • Conversions between Euler, Trigonometric and algebraic notation
  • tan() and arctan()

I have written a simple demo app called Complex Calculator that is a simple calculator for Complex numbers.

Vector and Matrix class

There is not much new for the Vector classes. The Matrix class has some new features some of which need to be tested.

License

The stable release will be available with two licenses like the other Milestones of LinAlg APi. The GPL and CDDL license.

Demos

I will try to upload the demo apps on the project hompage with screenshots.



db4j: Simple Database API for Java

Posted by alexanderschunk on September 28, 2007 at 12:04 PM | Permalink | Comments (6)

db4j: A simple Database API

If you are working a lot with Java DB then you repeatedly perform a few tasks every time and some only once.

For instance establishing a connection with a database and open a table of database usually happens at least once until you are working with more than one database. With JDBC you need to do the following for establishing the connection:

 try{ 
    conn = DriverManager.getConnection(dbname, username, password);
         return SQL_DB_OPEN_ERROR;
      }catch(SQLException e){
          System.out.println("Error! Unable to connect to " + dbname);
          System.out.println("Cause: " + e.getSQLState());
      } 

Given a Connection object called conn the code above is used for setting up a connection with a database with your username and password.

With db4j you can connect to a database as follows:

DBConnection db = new DBConnection();
String dbname = "BeispielDB.txt";
String usrname = "admin";
String password = "adminadmin";
String constring = "sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn;
try{
   db.connect(conn,constring, "admin", "adminadmin");
        db.open(conn, constring, usrname, password);
       }catch(Exception e){
           
       }

This simplifies the connection process to creating an object of class DBConnection and calling its open() method with a few parameters.

The DBConnection class offers basic methods for connecting to a database, open a database and close the connection.

To reduce programming with JDBC or derby db4j offers a set of classes that consists of the following classes:

  • DBConnection
  • DBActions
  • DBDriverInfo
  • DBLogger
  • DBMetadata

The name of these classes are almost self describing. The DBActions class provides database transactions such as Auto-Commit, Rollback etc.

Note that your DBMS might not support all these featurs so have to consult your DBMS documentation.

DBLogger is a simple Logger class that uses JDBC Logger methods. The DBDriverInfo provides information about the database driver.

In a future release i will add a statement class and some utility methods for retrieving and setting database values.



VisGraph: Visualization of Math functions

Posted by alexanderschunk on September 24, 2007 at 01:09 PM | Permalink | Comments (1)

VisGraph: Simple, Tiny, Visual

VisGraph API is a simple and tiny API for plotting standard math functions like sin(), cos(), abs() etc. that are provided by the java.lang.math package.

VisGraph implemens all methods as static methods so you can use them like the ones provided in java.lang.Math.

//plot a sin curve in green given the points below
double[] points = {2, 3, 4, 5, 6, 9, 12};
plotSin(points, BasicMath.TWO_PI, Color.green);

This plots a sin curve with the points given in a range of TWO_PI which is a constant of the class BasicMath in which plotSin() is defined.

With VisGraph you can plot i.g. a line that is defined as a Vector or as Points.

//plot a line defined as two points in blue
Point2D one = new Point2D(2, 4); //define a Point 
Point2D two = new Point2D(3, 1); //another point
plotPoint2D(one, two, Color.red); 

There are similar methods for Vector types:

//plot a line defined as two vectors
Vector2D x = new Vector2D(3, 1);
Vector2D y = new Vector2D(2, 1);
plotVector2D(x, y, Color.blue); 

Since all methods are static you can call them in your app without any object. VisGraph uses the Java 2D API methods for drawing the plots so its a bit limited to Java 2D capabilities.



AMD announces LWP for Java

Posted by alexanderschunk on September 10, 2007 at 08:17 AM | Permalink | Comments (0)

LWP: Light weight profiling

AMD - and also Intel - are working on profiling technologies that gather information on running programs and use this data to improve application performance.

The AMD technology is called LWP and is official avaiable as a PDF from the AMD developer site. The LWP technology extends the AMD 64 Bit architecture and includes two new instructions and statistics features implemented in the CPU.

Intel seems to be working on a similar technology called Rockton Technology but this has not been officially announced yet.

According to official AMD announcements LWP will improve Java or managed code however AMD itself has no official data or figures published. But even its not official nor actually implemented this new technology sounds interesting.

Given this technology and a monitor application on your PC that watches and plots the gathered CPU and or memory data of applications - in particular multi-cores - it will be easier to improve performance of Java and managed applications.

AMD itself says that LWP focuses in particular on Java and .NET managed code. One thing thats interesting is that LWP does not allow applications to use LWP statistics of other applications so each application has its own LWP statistics.

AMD will release a first 64 Bit CPU with LWP in 2008. Intel did not publish any figures yet they say that Rockton Technology does not even exist.

Anyway if AMD will implement LWP on their 64 Bit systems developers writing code for this platform might gain a big plus of performance for their apps.



LinAlg API: SIMD and Update 3

Posted by alexanderschunk on September 08, 2007 at 04:28 AM | Permalink | Comments (0)

LinAlg API: Milestone 1 update 3

Half a month ago i announced update 2 of Milestone 1 of the LinAlg API. Update 2 included some utility methods for Complex Numbers and some other helpful methods.

New Features

With update 3 i have added a method called Negate() to the Vector classes with which you can simply negate the component values of a Vector:

Vector3D x = new Vector3D(2, 3, 1);
x.Negate(); // = -2, -3, -1

This is also avaiable for 2D Vectors.I have also added some things to the Matrix class. With update 3 you can create a matrix from a two-dimensional array:

double[2][2] mat = {{2, 1}, {3, 1}};
Matrix m = new Matrix(mat); //create matrix from array

I have also added some operations for array based matrices like +, -, * etc.

The Complex class now contains methods to compute Complex numbers in trigonomial and Euler notation.

SIMD for LinAlg API

Besides these "raw" Java implementations i have developed a tiny C library to detect SIMD features on Intel and AMD CPUs. In my last Blog on SIMD i said that SIMD can process 2 DWORD values. This is not correct. In fact, with SIMD you can process up to 4 32 Bit DWORD values which means that SIMD works with 128 Bit sized registers. Thats why SIMD can perform i.g. certain Vector operations much faster than the normal CPU registers.

Another thing is that AMD produces 64 Bit processors only that support SSE so in the end, things are easier because i only need to check for SSE. I dont know if AMD still uses 3DNOW so the Programmers Manual of AMD only mentions SSE.

Basically, the C library i have developed consists of a few functions that call CPUID instruction and perform a few assembly operations. In General, all you have to do is to use the test and mov instruction to check i.g. if SSE or SSE3 is avaiable.

Update 3 of LinALg API will be available next week and i will also upload the C library and the GUI application. Note: the GUI application is written with MFC so it only works on Windows.



Compatiblity vs. Diversity: Will OpenJDK help Java survive?

Posted by alexanderschunk on September 05, 2007 at 01:30 AM | Permalink | Comments (1)

Compatibility or Diversity

One thing thats right in Davids comment is that as soon as there are many different distributions of one Software product this will hurt compatiblity to the original product. One reason why people develop different implementations of an existing product is that they think the original product (i)does not offer the thing they need and/or (ii)the feature works bad or not as expected.

This goes for all kinds of software thats around there today. No matter if you write Tools, APIs, Frameworks, etc. you can bet that sooner or late there will be improvement, extension, enhancement or whatsoever.

OpenSource: The root of the War

One thing David omits in his comment was that the OpenSource movement - driven by the emergence of Linux - has helped Linux encountering the Desktop and thats why so many poeple use it today. So diversity and open systems also have a good point. If Linux would not exist, Microsoft would be the Monopolist you fear. And with Linux many useful Unix tools discovered the Desktop and gain a much broader popularity.

So with open systems you have the freedom of choice to pick the one you like and leave alone the ones you dont. Just imagine there would only be one OS to make things worse, consider this would be Windows. All people on this planet -including the SUN engineers - would have to use this mor or less stable operating system. Unless you throw it away and write your own. And... see grow up another incompatible system in the world.

OpenSource and Compatiblity

I dont say that software diversity is bad or compatiblity stops diversity but keeping compatiblity and allowing diversity is a thing all major software developers and vendors have to face.

Its also true that its software vendors own failure that different and incompatible versions of a software exist. Its true that for the Windows plattform there are today - at least - three different kinds of frameworks and APIs available that are more or less incompatible: .NET, MFC, and Windows API. Yes you are reading right... the MFC is still alive :).

On the other hand, if low-level APIs such as Windows API would not be available it would be hard to write certain applications that you cannot develop using .NET only.

Since Java is a cross-plattform programming Platfrom - not just an API or language its another story. Sure the existance of other opensource implementations like the Classpath project or other Java VMs does not make lifer easier for developer however, i believe that most Java developers are using the SUN Java Platform.

So in the end i think that Java wont suffer the same silly war than Unix because its already in widespread use on different platforms and it was initially developed with the scope of cross-platform usability while Unix was not.

And another thing thats important is that SUN has opened the Java TCK Compatibility tests for OpenJDK so this might be a resort to help ensuring compability to the original Java platform. So, finally, if SUN opensources Java it has to solve the problem of OpenSource freedom and commercial interests.



SIMD for LinAlg API: Part I

Posted by alexanderschunk on September 02, 2007 at 02:23 AM | Permalink | Comments (5)

SIMD: Introduction

For those that are not familiar with SIMD, which is short for Single Instruction Multiple Data i will give a short introduction. If you never worked with low-level assembly or C code, SIMD is a bit hard to understand but i will try to explain it. Basically, using SIMD requires an understanding of how a CPU works and how a CPU processes data between memory and its various registers. But this is just the beginning of the story. Since SIMD is implemented by various CPU vendors like Intel and AMD, there are, unfortunately, different types of SIMD instruction sets for different CPU architectures.

Why SIMD

SIMD was introduced to improve speed of data processing on PCs in particular for those applications that need to perform a lot of complex opereations and process a lot of data fast. Those applications are for instance Games, Animations and other Mulitmedia applications.

If you run those applications on a normal CPU without SIMD the CPU usually only processes one instruction at time, that is, per CPU tick. Sometimes the applications mentioned above require to process more than one data - or, multiple data - per tick. Thus, the idea of SIMD was born. If you are using SIMD in your application, this basically means that you are processing multiple data in parallel by one single CPU / FPU instruction.

Sounds nice right? So why do not all applications benefit from this great technology? Well, to be honest, its not the problem of technology rather than a problem of implementation. If you want to support SIMD, you will have provide an assembly language implementation of the functions that require fast CPU processing.

Today, there are various libraries available i.g. from Intel that provide common math functions that support SIMD, yet, if your API only uses a few functions that require SIMD support, well using another lib just would bloat up your own code.

MMX, SSE and 3DNOW

As i said above, there are different SIMD implementations availabe today. The two most popular implementations used, in particular in 3D Games or real-time applications are Intels Streaming SIMD Extensions called SSE and AMDs 3DNOW. MMX which is short for Multi Media Extension is not that much used today.

Intel and AMD are the two global players on the CPU market today so if you write a cross-plattform API you will have to support these CPU architectures.

Both, SSE and 3DNOW make use of special FPU - Floating Point Unit - registers that can perform complex math operations, such as Vector computation. For example, if you want to to compute the square root, that is the length of a Vector using SIMD, you can move the values of the Vector components into the corresponding register and look up the square root in a Look up table of the CPU. This is faster than computing it by using i.g. the Java Math.sqrt() method..

64 Bit FPU data types

The most important fact why SIMD is so much faster than SISD - which means Single Instruction Single Data - is that it makes use of special 64 Bit registers that can store and process two 32 Bit values, also known as DWORD or double word. These registers are all implemented on the FPU, so the CPU does not need to deal with them. This also has the advantage that the CPU can process normal application data and can delegate complex math operations to the FPU. So, basically, a fast FPU and huge RAM memory will speed up any 3D application.

32 and 64 Bit Archtictures

With the emergence of x64 Bit architectures, things become more complicated. If you want to support any imaginable PC architecture you have to provide at least implementations for Intel x32 and 64 Bit and AMD x32 and x64 bit architectures. So you will end up at least with 4 small projects that almost provide the same functionality.

Java, C, Assembly

Now that you know your various "stakeholders" at the system side, the other "stakeholders" at the software side show up. If you want to support any SIMD technology from above, you will have to write a JNI wrapper in C that implements the assembly code. Java - currently - lacks the ability to load native assembly files, so you have to use C.

Conclusion

What do we learn from that? Well there are many aspects to consider and many pitfalls to fall in, but, actually, as you will see in another Blog, things are not that much complicated, at least, if you have already had a look at SIMD before. Basically, you will need a few C structs and some functions that provide the assembly code and write a Java class that loads the library including error handling etc. The most important thing when working with SIMD is the processor type detection and the processor feature detection using the CPUID instruction. CPUID instruction is available on all common processor types.

The Java JNI Tutorial provides a good introduction to the Java invocation API and on Intel Developer Site and AMD homepage you will find valuable information on how to deal with various processors and their features.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds