Click here to Skip to main content
15,885,885 members
Articles / High Performance Computing / Vectorization

A C++ String Class

Rate me:
Please Sign up or sign in to vote.
4.96/5 (29 votes)
3 Jan 2015CPOL13 min read 120.7K   2.6K   93  
A fast, reference counted, copy-on-write string class
#include "stdafx.h"

/*
 * -- SuperLU MT routine (version 2.0) --
 * Lawrence Berkeley National Lab, Univ. of California Berkeley,
 * and Xerox Palo Alto Research Center.
 * September 10, 2007
 *
 */
#include <stdlib.h>
#include "hnum_pcsp_defs.h"
#include "hnum_cblas.h"

namespace harlinn
{
    namespace numerics
    {
        namespace SuperLU
        {
            namespace Complex
            {
                /*
                 * Generate a banded square matrix A, with dimension n and semi-bandwidth b.
                 */
                void cband(int n, int b, int nonz, complex **nzval, int **rowind, int **colptr)
                {
                    int iseed[] = {1992,1993,1994,1995};    
                    register int i, j, ub, lb, ilow, ihigh, lasta = 0;
                    complex *a;
                    int    *asub, *xa;
                    complex *val;
                    int    *row;
    
                    printf("A banded matrix.");
                    // Allocate storage
                    callocateA(n, nonz, nzval, rowind, colptr); 
                    a    = *nzval;
                    asub = *rowind;
                    xa   = *colptr;
                    ub = lb = b;
    
                #if 0 // EH: Given the content of the iseed array, this code is just a waste of cpu cycles
                    for (i = 0; i < 4; ++i) 
                    {
                        iseed[i] = abs( iseed[i] ) % 4096;
                    }
                    if ( iseed[3] % 2 != 1 ) 
                    {
                        ++iseed[3];
                    }
                #endif

                    for (j = 0; j < n; ++j) 
                    {
	                    xa[j] = lasta;
	                    val = &a[lasta];
	                    row = &asub[lasta];
	                    ilow = SUPERLU_MAX(0, j - ub);
	                    ihigh = SUPERLU_MIN(n-1, j + lb);
	                    for (i = ilow; i <= ihigh; ++i) 
                        {
	                        val[i-ilow].r = float(dlaran_(iseed));
	                        row[i-ilow] = i;
	                    }
	                    lasta += ihigh - ilow + 1;
                    } /* for j ... */
                    xa[n] = lasta;
                }

                /*
                 * Generate a block diagonal matrix A.
                 */
                void cblockdiag(int nb, /* number of blocks */
	                   int bs, /* block size */
	                   int nonz, complex **nzval, int **rowind, int **colptr)
                {
                    int iseed[] = {1992,1993,1994,1995};    
                    register int i, j, b, n, lasta = 0, cstart, rstart;
                    complex *a;
                    int    *asub, *xa;
                    complex *val;
                    int    *row;
    
                    n = bs * nb;
                    printf("A block diagonal matrix: nb %d, bs %d, n %d\n", nb, bs, n);
                    callocateA(n, nonz, nzval, rowind, colptr); /* Allocate storage */
                    a    = *nzval;
                    asub = *rowind;
                    xa   = *colptr;

                #if 0 // EH: Given the content of the iseed array, this code is just a waste of cpu cycles
                    for (i = 0; i < 4; ++i) 
                    {
                        iseed[i] = abs( iseed[i] ) % 4096;
                    }
                    if ( iseed[3] % 2 != 1 ) 
                    {
                        ++iseed[3];
                    }
                #endif
                    for (b = 0; b < nb; ++b) 
                    {
	                    cstart = b * bs; /* start of the col # of the current block */
	                    rstart = b * bs; /* start of the row # of the current block */
	                    for (j = cstart; j < cstart + bs; ++j) 
                        {
	                        xa[j] = lasta;
	                        val = &a[lasta];
	                        row = &asub[lasta];
	                        for (i = 0; i < bs; ++i) 
                            {
                                val[i].r = float(dlaran_(iseed));
		                        row[i] = i + rstart;
	                        }
	                        lasta += bs;
	                    } /* for j ... */
                    } /* for b ... */
    
                    xa[n] = lasta;
                }
            };
        };
    };
};            

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions