Invisible function in my main

Hi there,
I've got the following main function. F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <vector>
using std::vector;

//declarations:
void initConfig(vector<vector<int> >& prelattice, int nL, int nN);
void warmUp(vector<vector<int> >& prelattice, int nL, int nN, bool inside=true);

int main() {
  int nN = 10; //number of columns
  int nL = 15; //number of rows
  vector<vector<int> > lattice(nL, vector<int>(nN)); //declaration of lattice
  initConfig(lattice, nL, nN); //creation of random lattice
  warmUp(lattice, nL, nN); //warming up the system
  return 0;
}


For some reason I cannot manage to make the function warmUp work. The two functions are compiled and linked to the main program accordingly... no complaints from the compiler. Since I do not get an error message, I am quite lost!

Any ideas/advice?

Thanks a million!
I advice to ask a clairvoyant.
Last edited on
...meaning, show us the code.
Thank you guys!

The warmUp function is contained in a file with this source code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <ctime>
#include <iostream>
#include <vector>

//declarations
bool accepted(int nEg_core, unsigned int nSeed);

void warmUp(std::vector<std::vector<int> >& prelattice, int nL, int nN, bool inside=true) {
  unsigned long int nMax_sweep = 1000;
  unsigned long int nDouble_max = 2*nMax_sweep;
  std::cout<< nMax_sweep << std::endl;
  //controlers
  unsigned int nInside_true=0;
  unsigned int nInside_false=0;
  unsigned int nControl_true=0;
  unsigned long int nControl_false=time(NULL);
  unsigned int nOut=0;

  //variables
  short int nSum_near;
  short int nEg_core;
  clock_t t1, t2, t3;
  t1 = clock();
  for (unsigned long int i=0;i<nDouble_max;++i) {
    nSum_near = 0;
    nEg_core = 0;

  //algorithm
  if (inside==true) {
    for (unsigned int r=1;r<nL-1;++r) {
      for (unsigned int c=1;c<nN-1;++c) {
	nSum_near = prelattice[r-1][c] + prelattice[r+1][c] + prelattice[r][c-1] + prelattice[r][c+1];
        nEg_core = nSum_near*prelattice[r][c];
	if (accepted(nEg_core,nControl_true++) == true)  prelattice[r][c] *= -1;
	else ++nControl_true;
      }
    }

    inside==false;
    ++nInside_true;
  }
  else {
    t2= clock();
      for (unsigned int c=0;c<nN-1;++c) {
	nOut = c-1;
	if (c-1<0) nOut = nN-1; 
	nSum_near = prelattice[nL-1][c] + prelattice[1][c] + prelattice[0][nOut] + prelattice[0][c+1];
        nEg_core = nSum_near*prelattice[0][c];
	if (accepted(nEg_core,nControl_false++) == true)  prelattice[0][c] *= -1;
      }
      for (unsigned int c=1;c<nN;++c) {
	nOut = c+1;
	if (c+1>nN-1) nOut = 0; 
	nSum_near = prelattice[nL-2][c] + prelattice[0][c] + prelattice[nL-1][c-1] + prelattice[nL-1][nOut];
        nEg_core = nSum_near*prelattice[nL-1][c];
	if (accepted(nEg_core,nControl_false++) == true)  prelattice[nL-1][c] *= -1;
      }
      for (unsigned int r=1;r<nL;++r) {
	nOut = r+1;
	if (r+1>nL-1) nOut = 0; 
	nSum_near = prelattice[r][nN-1] + prelattice[r][1] + prelattice[r-1][0] + prelattice[nOut][0];
        nEg_core = nSum_near*prelattice[r][0];
	if (accepted(nEg_core,nControl_false++) == true)  prelattice[r][0] *= -1;
      }
      for (unsigned int r=0;r<nL-1;++r) {
	nOut = r-1;
	if (r-1<0) nOut = nL-1; 
	nSum_near = prelattice[r][nN-2] + prelattice[r][0] + prelattice[nOut][nN-1] + prelattice[r+1][nN-1];
        nEg_core = nSum_near*prelattice[r][nN-1];
	if (accepted(nEg_core,nControl_false++) == true)  prelattice[r][nN-1] *= -1;
      }

    inside==true;
    ++nInside_false;
  }
  }  
  t3 = clock();
  float sweep = (float(t3)-float(t1))/CLOCKS_PER_SEC;
  float interior = (float(t2)-float(t1))/CLOCKS_PER_SEC;
  float exterior = (float(t3)-float(t2))/CLOCKS_PER_SEC;
  std::cout << "Sweep: " << sweep << "--- interior: " << interior << "--- exterior: " << exterior << std::endl;
}

I does not print anything... not even the first std::cout that I placed to check. It seems to me that the function is not being executed at all. All being said, although now the compiler does not return any error message, before it was stating that warmUp was undefined in my main. After I included the default argument in the declaration of the function in main it does not complain... but it does not execute warmUp at all :(. It's sad.
Is it very difficult to insert a print message between the functions' calls that to be sure that the problem is in function warmUp?

1
2
  initConfig(lattice, nL, nN); //creation of random lattice
  warmUp(lattice, nL, nN); //warming up the system 
Last edited on
dbachito wrote:
Since I do not get an error message, I am quite lost!


Can you learn to use the debugger - should be quite easy if you are using an IDE. You can step through code 1 line at a time, keep an eye on the values of your variables & deduce where it all went wrong.

Vlad's suggestion is probably easier right now, (I always look forward to reading what he says). But knowing how to use a debugger is an essential skill, and by far the quickest way of solving runtime errors - save yourself days of problems.

Hope all goes well.
Topic archived. No new replies allowed.