how to configure NIST TNT into cygwin gcc environment

NIST TNT and JAMA are very useful libraries designed for complex matrix based computation. The libraries are purely headers containing template based classes and subroutines. To configure the TNT into a cygwin/gcc programming environment, the following can be done:

1. download TNT and JAMA from nist.gov (http://math.nist.gov/tnt/download.html)

2. extract the header files into /usr/local/include/tnt

3. test a cpp file:

#include <tnt/tnt.h>
#include <iostream>
using namespace TNT;
using namespace std;
int main(void)
{
int M = 3;
int N = 3;
Array2D< double > A(M,N, 0.0); /* create MxN array; all zeros */

for (int i=0; i < M; i++)
for (int j=0; j < N; j++)
A[i][j] = i*10+j; /* initalize array values */

Array2D< double > B = A.copy(); /* create a new copy */

Array2D< double > C(B); /* create a new view of B */
/* Both arrays (B & C) share data */
for (int i=0; i<M; i++)
for (int j=0; j<N; j++)
cout<<"A["<<i<<"]["<<j<<"] = "<<A[i][j]<<endl;
return 0;
}

4. write a makefile

CPP = g++
OFLAG = -Wall -o
LFLAG = -l
IFLAG = -I
LIBFLAG = -L
LIBDIR = /usr/local/lib/
INCLUDEDIR = /usr/local/include/TNT/
DEBUGF = -g -D DEBUG
DEBUG = no

.SUFFIXES: .exe .cpp
.cpp.exe:
$(CPP) $(OFLAG) $@ $<
$@

try.exe: try.cpp
$(CPP) $(IFLAG) $(INCLUDEDIR) $(OFLAG) try.exe try.cpp

5. build, and run the try.exe. The result shows:

A[0][0] = 0
A[0][1] = 1
A[0][2] = 2
A[1][0] = 10
A[1][1] = 11
A[1][2] = 12
A[2][0] = 20
A[2][1] = 21
A[2][2] = 22

Advertisements

2 thoughts on “how to configure NIST TNT into cygwin gcc environment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s