C++ programming

Joseph Landman landman at scalableinformatics.com
Mon Oct 21 12:56:48 PDT 2002


On Mon, 2002-10-21 at 14:07, Garriss, Michael wrote:

> if ( !myMap.containsKey( key ) )
> 	myMap.put( key, new Integer( 1 ) );
> else {
> 	Integer count = (Integer) myMap.get( key );
> 	int icount = count.intValue( );
> 	myMap.put( key, new Integer( ++icount ) );
> }

[...]

> I would love to see the FORTRAN version of this code....

c assuming the existance of the relevant functions from somewhere else 
c (ignore the library behind the curtin)
c
c function: myMap_containsKey is a boolean function that returns a true
c           if the key is within the map (list/hash/whatever).
c function: myMap_get_int returns the current value of the item pointed
c           to key
c subroutine: myMap_put places a new key wit a particular value into the
c             map (list/hash/whatever)
c
	if ( .not. myMap_containsKey( key ) ) then
 	   call myMap_put( key, 1 )
	  else 
	   count = myMap_get_int( key )
	   count=count+1
	   call myMap_put( key, count )
	endif

The issue is not the code, it is whether you have to hand code the
library calls (myMap, etc) yourself.  In Fortran, you would need to code
these libraries or borrow someone elses code to do this.  Better still
is to avoid re-inventing the wheel, and use someones prewritten working
library to avoid writing code yourself.

The C++ version is far more readable, and is similar to how Perl,
Python, and others do it as well.  

Then again, I wouldnt be writing HPC code in Java to begin with so I
think the example is moot.  Hope I didnt miss the point of the messages
here...


-- 
Joseph Landman, Ph.D
Scalable Informatics LLC
email: landman at scalableinformatics.com
  web: http://scalableinformatics.com
phone: +1 734 612 4615




More information about the Beowulf mailing list