templates/parallel programming

Hi;

The following code has 2 template functions in the same header. I would like to ask whether there is any problem with writing template<int N> before each one. Also is there a way of telling the compiler to assume all functions are template with only one line?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Summation Density
template<int N>
double Calc1(CVector vPos[N],double dMass[N], int iIndex, double rho[],double h){
	using namespace std;
    rho[iIndex] = 0;
    for (int i = 0; i < N; i++){
        rho[iIndex] += (dMass[i])*KrnlCS(vPos, iIndex, i, h);
    }
    return rho[iIndex];
}

//Summation Density (more accurate)
template<int N>
double Calc2(CVector vPos[N],double dMass[N], int iIndex, double rho[],double h){
	using namespace std;

}


Also, I didn't know whether parallel programming comes under beginner or intermediate but I would like to implement my code on multiple nodes. I have a basic understanding in which cases I can use parallel programming, would like to learn more but first I would like someone more experienced to advise whether openMP is a decent package to use for this. And am I correct in saying that openMP is included in microsoft visual 2010 with no extra downloads?

Thank you for reading this, appreciate any advise.

Krahl
There is no issue with doing what you are doing. You must use the "template<>" syntax for each function; there is no way to elide.

I can't answer the question on openMP though.
Wasn't it impossible to declare templated functions in a header file and use it in the source file?

I remember that I had to copy-paste all the templated functions from a header to a source in order to get it to work...
Last edited on
Thank you jsmith.

@Ramses12 it works for me just fine.
Topic archived. No new replies allowed.