In the following snippet, when I print the posUVZ values, they are non-zero but after I pass them to ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) all the pos3D values happen to be zero. Any though on why is this happening and how to fix it?
/***
Reads the depth data from the sensor and fills in the matrix
***/
void SR300Camera::fillInZCoords()
{
PXCImage::ImageData depthImage;
PXCImage *depthMap = sample->depth;
depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
Projection * projection = device->CreateProjection();
unsigned int wxhDepth = depth_width * depth_height;
// create the array of depth coordinates + depth value (posUVZ) within the defined ROI
PXCPoint3DF32* posUVZ = new PXCPoint3DF32[wxhDepth];
pxcU16 *dpixels = (pxcU16*)depthImage.planes[0];
unsigned int dpitch = depthImage.pitches[0] / sizeof(pxcU16); /* aligned width */
for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
{
for (unsigned int xx = 0; xx < depth_width; xx++, k++)
{
posUVZ[k].x = (pxcF32)xx;
posUVZ[k].y = (pxcF32)yy;
posUVZ[k].z = (pxcF32)dpixels[yy * dpitch + xx];
// cout << "xx is " << posUVZ[k].x << endl;
// cout << "yy is " << posUVZ[k].y << endl;
// cout << "zz is " << posUVZ[k].z<< endl;
}
}
// convert the array of depth coordinates + depth value (posUVZ) into the world coordinates (pos3D) in mm
PXCPoint3DF32* pos3D = new PXCPoint3DF32[wxhDepth];
projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D);
/*
if (projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) < PXC_STATUS_NO_ERROR)
{
delete[] posUVZ;
delete[] pos3D;
cout << "projection unsucessful";
return;
}
*/
for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
{
for (unsigned int xx = 0; xx < depth_width; xx++, k++)
{
cout << "xx is " << pos3D[k].x*1000.0 << endl;
cout << "yy is " << pos3D[k].y*1000.0 << endl;
cout << "zz is " << pos3D[k].z*1000.0 << endl;
xyzBuffer.push_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
}
}
/*
for (int idx = 0; idx < wxhDepth; idx++) {
cout << "x is " << pos3D[idx].x*1000.0 << endl;
cout << "y is " << pos3D[idx].y*1000.0 << endl;
cout << "z is " << pos3D[idx].z*1000.0 << endl;
xyzBuffer.push_back(cv::Point3f(pos3D[idx].x, pos3D[idx].y, pos3D[idx].z));
}
*/
//xyzMap = cv::Mat(xyzMap.size(), xyzMap.type, &pos3D);
xyzMap = cv::Mat(xyzBuffer);
cout << "xyzMap = " << endl << " " << xyzMap << endl << endl;
projection->Release();
delete[] posUVZ;
delete[] pos3D;
};
Here's the correct answer to get the xyzMap from the Depth image UVmap:
PXCImage::ImageData depthImage;
depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
depth_width = imgInfo.width;
depth_height = imgInfo.height;
num_pixels = depth_width * depth_height;
PXCProjection * projection = device->CreateProjection();
PXCPoint3DF32 *pos3D = new PXCPoint3DF32[num_pixels];
sts = projection->QueryVertices(depthMap, &pos3D[0]);
if (sts < Status::STATUS_NO_ERROR) {
wprintf_s(L"Projection was unsuccessful! \n");
sm->Close();
}
Related
GsVec curve_eval::eval_lagrange(float t, float numberofsegmentsn, const GsArray<GsVec>& ctrlpnts) //f(t) = sum of p.i * B.i(t)
{
//float interval = 1 / numberofsegmentsn; //so if 4, then 0.25
float interval = 1 / ctrlpnts.size();
//remember that for interval that is put in above, it's based on numbers of ctrlpnts
//for lagrange, let t
GsVec ft(0.0f, 0.0f, 0.0f);
int sizeofctrlpnts = ctrlpnts.size();
float result = 0;
std::cout << "interval = " << interval << " \\ number of segments = " << numberofsegmentsn << " \\ ctrlpnts.size() = " << ctrlpnts.size() << "\n";
float tt = 0;
float ti[50] = { 0 };
float tj[50] = { 0 }; //only this might be used
for (int x = 0; x < ctrlpnts.size(); x++) //changed from 'numberofsegmentsn'
{
tj[x] = tt;//
std::cout << "tt in tj[" << x << "]= " << tt << "\n";
tt = tt + interval;
}
float tb = 1;
tt = 1;
int i = 0;
for (int i = 0; i < ctrlpnts.size(); i ++)
{
tt = 1;
tb = 1;
for (int j = 0; j < ctrlpnts.size(); j++) //
{
if (i != j)
{
std::cout << "Before cal: i = " << i << " :: j = " << j << " :: tt = " << tt << " :: tb = " << tb << " :: t = " << t << " :: tj[i" << j << "] = " << tj[j] << " :: tj[j" << i << "] = " << tj[i] << "\n";
tt = (t - tj[j]) * tt;
tb = (tj[i] - tj[j])* tb;
std::cout << "After cal: tt = " << tt << " :: tb = " << tb << "\n";
}
//t gotta change
}
result = tt / tb;
ft = ft+(ctrlpnts[i]*result);
}
return ft;
Above is my written algorithm for Lagrange function for opengl.
Following link is the screenshot of the formula that i had to impliment, http://imgur.com/gkuaxVm.
I have been tweaking it for awhile, and i can't seem to find what is wrong with it.
I have a simple main code that gives me segmentation fault when calling a function. In the following code, I have two functions, the first one works correctly but the program doesn't enter the second one and gives me segmentation fault error. Is there any reason for that? I have made sure about the following:
The variables o and c are not out of bound.
cn is initialized correctly.
I have a read-only access to cm and argv. Plus it does not even enter the function evaluate
Here is the code:
void print_cm(vector<vector<int> > *cm, char* gtf);
void evaluate(vector<vector<int> > *cm, char* gtf);
int main(int argc, char** argv)
{
int o = 2; // It is initialized
int c = 4; // It is initialized
vector<vector<int> > cm; // It is initialized
if (argc>4)
print_cm(&cm, argv[o]);
if (argc>4)
{
cout << argv[c] << endl; // Works
// The following also works
for (int i=0; i<cm.size(); i++)
for (int j=0; j<cm[i].size(); j++)
cout << cm[i][j] << " ";
// The following causes segmentation fault;
evaluate(&cm, argv[c]);
}
return 0;
}
void evaluate(vector<vector<int> > *cm, char* gtf)
{
// Read-only access to cm and gtf
}
void print_cm(vector<vector<int> > *cm, char* gtf)
{
// Read-only access to cm and gtf
}
Here is the complete code:
#include "includes/Utility.h"
#include "includes/Graph.h"
void print_cm(vector<vector<int> > *cores, char* output);
void evaluate(vector<vector<int> > const *cm, char* gtf);
int main(int argc, char** argv)
{
int g = -1, c = -1, o = -1;
for (int i=1; i<argc-1; i++)
if (argv[i][0]=='-')
{
if (argv[i][1]=='g')
g = i + 1;
else if (argv[i][1]=='c')
c = i + 1;
else if (argv[i][1]=='k')
ki = i + 1;
else if (argv[i][1]=='s')
si = i + 1;
else if (argv[i][1]=='o')
o = i + 1;
}
Graph G;
if (c>0) G.read_input(argv[g], argv[c]);
else G.read_input(argv[g]);
if (ki > 0)
{
int k = atoi(argv[ki]);
cout << k << endl;
}
if (si > 0)
{
int s = atoi(argv[si]);
cout << s << endl;
}
// Find communities
vector<vector<int> > cores;
G.partitioning(&cores);
if (o>0)
print_cm(&cores, argv[o]);
if (c>0)
{
cout << "here" << endl;
for (size_t i=0; i<cores.size(); i++)
for (size_t j=0; j<cores[i].size(); j++)
if (cores.at(i).at(j)<0) cout << "here";
cout << "here" << endl;
evaluate(&cores, argv[c]);
}
}
return 0;
}
void print_cm(vector<vector<int> > *cores, char* output)
{
ofstream out;
out.open(output);
for(size_t i=0; i<(*cores).size(); i++)
{
for(size_t j=0; j<(*cores)[i].size(); j++)
out << (*cores)[i][j] << " ";
out << endl;
}
out.close();
return ;
}
void evaluate(vector<vector<int> > const *cm, char* gtf)
{
// we evaluate precision, recall, F1 and F2
vector<vector<int> > gt;
ifstream in;
char str[100000000];
in.open(gtf);
while(in.getline(str, 100000000))
{
stringstream s;
s << str;
int a;
gt.resize(gt.size()+1);
while (s >> a) gt[gt.size()-1].push_back(a);
}
in.close();
cout << "==================== Evaluation Results ====================" << endl;
int imax = 0;
for(size_t i=0; i<(*cm).size(); i++)
imax = max(imax, *max_element((*cm)[i].begin(), (*cm)[i].end()));
for(size_t i=0; i<gt.size(); i++)
imax = max(imax, *max_element(gt[i].begin(), gt[i].end()));
vector<bool> flag(imax, false);
vector<double> recall((*cm).size(), 0), precision((*cm).size(), 0), f1((*cm).size(), 0), f2((*cm).size(), 0);
int overlap;
double size = 0;
for(size_t i=0; i<(*cm).size(); i++)
{
// evaluate
size += (double) (*cm)[i].size();
for(size_t j=0; j<(*cm)[i].size(); j++)
flag[(*cm)[i][j]] = true;
double p, r, ff1, ff2;
for(size_t j=0; j<gt.size(); j++)
{
overlap = 0;
for(size_t k=0; k<gt[j].size(); k++)
if (flag[gt[j][k]]) overlap++;
p = (double) overlap / (double) (*cm)[i].size();
if (p > precision[i])
precision[i] = p;
r = (double) overlap / (double) gt[j].size();
if (r > recall[i])
recall[i] = r;
ff1 = (double) 2*(p*r)/(p+r);
if (ff1 > f1[i])
f1[i] = ff1;
ff2 = (double) 5*(p*r)/(4*p + r);
if (ff2 > f2[i])
f2[i] = ff2;
}
for(size_t j=0; j<(*cm)[i].size(); j++)
flag[(*cm)[i][j]] = false;
}
double Recall = 0, Precision = 0, F1 = 0, F2 = 0;
for(size_t i=0; i<(*cm).size(); i++)
{
Recall += recall[i];
Precision += precision[i];
F1 += f1[i];
F2 += f2[i];
}
cout << "+--------------+--------------+--------------+--------------+" << endl;
cout << "| " << setiosflags( ios::left ) << setw(10) << "Precision";
cout << " | " << setiosflags( ios::left ) << setw(10) << "Recall";
cout << " | " << setiosflags( ios::left ) << setw(10) << "F1-measure";
cout << " | " << setiosflags( ios::left ) << setw(10) << "F2-measure";
cout << " |" << endl;
cout << "| " << setiosflags( ios::left ) << setw(10) << Precision/(*cm).size() ;
cout << " | " << setiosflags( ios::left ) << setw(10) << Recall/(*cm).size();
cout << " | " << setiosflags( ios::left ) << setw(10) << F1/(*cm).size();
cout << " | " << setiosflags( ios::left ) << setw(10) << F2/(*cm).size();
cout << " |" << endl;
cout << "+--------------+--------------+--------------+--------------+" << endl;
cout << "Number of communities: " << (*cm).size() << endl;
cout << "Average community size: " << size/(*cm).size() << endl;
return ;
}
char str[100000000];
This is in your evaluate function. This are 100 million bytes, or about 95 MB that you're allocating on the stack.
Typical stack sizes are far less than that, around 1 MB.
So apart from possible other problems this is most likely causing a stack overflow.
When entering the function, the stack frame gets extended to be large enough to hold the local variables. As soon as the stack is used then (to write a default value) you're accessing invalid (non stack, thankfully protected) memory.
I have been working on head pose estimation on depth data. And I have read G Fanelli's paper-"Real Time Head Pose Estimation from Consumer Depth Cameras" "Real Time Head Pose Estimation with Random Regression Forests". I test the data and the code Fanelli published on the website(http://www.vision.ee.ethz.ch/~gfanelli/head_pose/head_forest.html). However when I run the code, there is a problem. The error information is "usage: ./head_pose_estimation config_file depth_image". I think it is about file reading but I don't how to fix it.
and the code is like this:
int main(int argc, char* argv[])
{
if( argc != 3 )
{
cout << "usage: ./head_pose_estimation config_file depth_image" << endl;
exit(-1);
}
loadConfig(argv[1]);
CRForestEstimator estimator;
if( !estimator.loadForest(g_treepath.c_str(), g_ntrees) ){
cerr << "could not read forest!" << endl;
exit(-1);
}
string depth_fname(argv[2]);
//read calibration file (should be in the same directory as the depth image!)
string cal_filename = depth_fname.substr(0,depth_fname.find_last_of("/")+1);
cal_filename += "depth.cal";
ifstream is(cal_filename.c_str());
if (!is){
cerr << "depth.cal file not found in the same folder as the depth image! " << endl;
return -1;
}
//read intrinsics only
float depth_intrinsic[9]; for(int i =0; i<9; ++i) is >> depth_intrinsic[i];
is.close();
Mat depthImg;
//read depth image (compressed!)
if (!loadDepthImageCompressed( depthImg, depth_fname.c_str() ))
return -1;
Mat img3D;
img3D.create( depthImg.rows, depthImg.cols, CV_32FC3 );
//get 3D from depth
for(int y = 0; y < img3D.rows; y++)
{
Vec3f* img3Di = img3D.ptr<Vec3f>(y);
const int16_t* depthImgi = depthImg.ptr<int16_t>(y);
for(int x = 0; x < img3D.cols; x++){
float d = (float)depthImgi[x];
if ( d < g_max_z && d > 0 ){
img3Di[x][0] = d * (float(x) - depth_intrinsic[2])/depth_intrinsic[0];
img3Di[x][1] = d * (float(y) - depth_intrinsic[5])/depth_intrinsic[4];
img3Di[x][2] = d;
}
else{
img3Di[x] = 0;
}
}
}
g_means.clear();
g_votes.clear();
g_clusters.clear();
string pose_filename(depth_fname.substr(0,depth_fname.find_last_of('_')));
pose_filename += "_pose.bin";
cv::Vec<float,POSE_SIZE> gt;
bool have_gt = false;
//try to read in the ground truth from a binary file
FILE* pFile = fopen(pose_filename.c_str(), "rb");
if(pFile){
have_gt = true;
have_gt &= ( fread( >[0], sizeof(float),POSE_SIZE, pFile) == POSE_SIZE );
fclose(pFile);
}
//do the actual estimate
estimator.estimate( img3D,
g_means,
g_clusters,
g_votes,
g_stride,
g_maxv,
g_prob_th,
g_larger_radius_ratio,
g_smaller_radius_ratio,
false,
g_th
);
cout << "Heads found : " << g_means.size() << endl;
//assuming there's only one head in the image!
if(g_means.size()>0){
cout << "Estimated: " << g_means[0][0] << " " << g_means[0][1] << " " << g_means[0][2] << " " << g_means[0][3] << " " << g_means[0][4] << " " << g_means[0][5] <<endl;
float pt2d_est[2];
float pt2d_gt[2];
if(have_gt){
cout << "Ground T.: " << gt[0] << " " << gt[1] << " " << gt[2] << " " << gt[3] << " " << gt[4] << " " << gt[5] <<endl;
cv::Vec<float,POSE_SIZE> err = (gt-g_means[0]);
//multiply(err,err,err);
for(int n=0;n<POSE_SIZE;++n)
err[n] = err[n]*err[n];
float h_err = sqrt(err[0]+err[1]+err[2]);
float a_err = sqrt(err[3]+err[4]+err[5]);
cout << "Head error : " << h_err << " mm " << endl;
cout << "Angle error : " << a_err <<" degrees " << endl;
pt2d_gt[0] = depth_intrinsic[0]*gt[0]/gt[2] + depth_intrinsic[2];
pt2d_gt[1] = depth_intrinsic[4]*gt[1]/gt[2] + depth_intrinsic[5];
}
pt2d_est[0] = depth_intrinsic[0]*g_means[0][0]/g_means[0][2] + depth_intrinsic[2];
pt2d_est[1] = depth_intrinsic[4]*g_means[0][1]/g_means[0][2] + depth_intrinsic[5];
}
return 0;
}
can anyone could tell me how to fix the problem?Thanks so much!
You should always read the readme.txt (here attached in head_pose_estimation.tgz) before testing an application:
To run the example code, type ./head_pose_estimation config.txt
data/frame_XXXX_depth.bin. The config.txt file contains all parameters
needed for the head pose estimation, e.g., the path to the forest, the
stride, and z threshold used to segment the person from the
background.
as the title, i don't know how to convert this struct into a class?
Also i've another problem, how can i convert the array Sets[][] and top[] into vector?
I tried, but i have problem with editing in a vector of [i] position.
//*******************************
// Class Kruskal *
//*******************************
class kruskal
{
private:
struct Edge {
//Arco: vertice V -> vertice U : peso W
int v, u, w;
Edge(int v, int u, int w) : v(v), u(u), w(w) {}
bool operator < (const Edge& c) const{
if (w != c.w)
return w < c.w;
if (v != c.v)
return v < c.v;
return u < c.u;
}
};
int n; //n. nodes
int nre; //n. edges
vector<Edge> edges; //vector contenente tutti gli archiì
vector<Edge> tree; //Albero che conterrà tutti gli archi dell'MST
int sets[100][10]; //matrice contente i sets (tagli)
int top[100]; //supporto alla matrice dei sets
public:
kruskal(){};
~kruskal(){ cout << "Grafo distrutto"; };
void read_graph();
void sort_edges();
void algorithm();
int find_node(int);
void print_min_span_t();
};
//*******************************************
// read_graph() *
// Legge in input n, nre, e i vari archi *
//*******************************************
void kruskal::read_graph()
{
cout << "Algoritmo di Kruskal" << endl;
cout << "Minimum Spanning Tree su Grafo non orientato e pesato" << endl << endl;
cout << "-Inserire numero di nodi e numero di archi: ";
cin >> n >> nre;
int v, u, w;
cout << "-Inserire vertice 1, vertice 2 e peso:" << endl;
for (int i = 0; i < nre; i++)
{
cin >> v >> u >> w;
if (w != 0)
{
edges.push_back(Edge(v, u, w));
}
}
//Print graph edges
cout << endl << endl << "Archi del grafo:" << endl;
for (unsigned int i = 0; i < edges.size(); i++)
{
cout << " < " << edges[i].v
<< " , " << edges[i].u
<< " > " << edges[i].w << endl;
}
}
//*******************************************
// sort_edges() *
// Ordina gli archi per peso con sort() *
//*******************************************
void kruskal::sort_edges()
{
sort(edges.begin(), edges.end());
//Print graph edges
cout << endl << endl << "Archi del grafo dopo l'ordinamento:" << endl;
for (unsigned int i = 0; i < edges.size(); i++)
{
cout << " < " << edges[i].v
<< " , " << edges[i].u
<< " > " << edges[i].w << endl;
}
}
//***********************************************
// algorithm() *
// Inizializza i sets (make-set) *
// Trova i sets dei due nodi (Find_node) *
// Controlla se i sets sono diversi (Findset) *
// Se si lo inserisce nel vector "tree" (MST) *
// E unisce i due sets (Union) *
// Altrimenti "scarta" l'arco *
//***********************************************
void kruskal::algorithm()
{
//Make-set
for (int i = 1; i <= n; i++)
{
sets[i][1] = i;
top[i] = 1;
}
cout << endl << "Avvio algoritmo di Kruskal:" << endl << endl;
for (unsigned int i = 0; i < edges.size(); i++)
{
int p1 = find_node(edges[i].v);
int p2 = find_node(edges[i].u);
//Findset(p1) != Findset(p2)
if (p1 != p2)
{
cout << "Arco preso nell'albero:"
<< " < " << edges[i].v << " , "
<< edges[i].u << " > " << endl << endl;
//Union
tree.push_back(Edge(edges[i].v, edges[i].u, edges[i].w));
//Union two sets
for (int j = 1; j <= top[p2]; j++)
{
top[p1]++;
sets[p1][top[p1]] = sets[p2][j];
}
top[p2] = 0;
}
else
{
cout << "Questo arco"
<< " < " << edges[i].v << " , "
<< edges[i].u << " > " << "forma un ciclo ed e' stato rimosso" << endl << endl;
}
}
}
//*******************************************
// find_node() *
// Trova il sets di appartenenza del nodo *
//*******************************************
int kruskal::find_node(int n)
{
for (int i = 1; i <= nre; i++)
{
for (int j = 1; j <= top[i]; j++)
{
if (n == sets[i][j])
return i;
}
}
return -1;
}
//*******************************
// print_min_span_t() *
//*******************************
void kruskal::print_min_span_t()
{
cout << endl << "Minimum Spanning Tree del grafo:" << endl;
for (unsigned int i = 0; i < tree.size(); i++)
{
cout << " < " << tree[i].v
<< " , " << tree[i].u
<< " > " << tree[i].w << endl;
}
}
As top is just the size of corresponding sets, you may remove top, and change std::vector<std::vector<int> > sets.
Then
MakeSet:
//Make-set
sets.resize(nre); // or n, not sure of the definition of each one...
for (std::size_t i = 0; i != nre; ++i)
{
sets[i].push_back(i);
}
UnionSet:
//Union two sets
sets[p1].insert(sets[p1].end(), sets[p2].begin(), sets[p2].end());
sets[p2].clear();
Find node:
int kruskal::find_node(int n) const
{
for (size_t i = 0; i != sets.size(); ++i)
{
if (std::find(sets[i].begin(), sets[i].end(), n) != sets[i].end())
{
return i;
}
}
return -1;
}
I have a matrix multiplication code that I am supposed to process in parallel. I have a code here that I believe should work but does not. It either causes segmentation faults or gives me all gibberish values. Can any one help? Thanks in advance.
//*******************STRUCTS AND GLOBAL VARIABLES*****************************//
struct Matrix
{
int d[SIZE][SIZE];
};
Matrix* matrix_addr[SIZE]; // array to store the address of the matrices
int n;
int m;
pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t my_cond = PTHREAD_COND_INITIALIZER;
//****************************THREAD******************************************//
void* calcTerm(void* arg)
{
pthread_mutex_lock(&my_mutex);
int sum = 0;
Matrix* m0 = (Matrix*) arg;
Matrix* m1 = (Matrix*) ((int*)arg + 1);
Matrix* m2 = (Matrix*) ((int*)arg + 2);
cout << endl << "Print\n" << endl;
print (m0);
for (int i = 0; i < SIZE; ++i)
{
cout << "\ni = " << i << "\tn = " << m1->d[n][i] << "\tm = " << m2->d[i][m] << endl;
sum = sum + (m1->d[n][i] * m2->d[i][m]);
}
cout << endl << endl << sum << endl;
m0->d[n][m] = sum;
pthread_mutex_unlock(&my_mutex);
cout << endl << "Going out of thread\n" ;
pthread_exit(NULL);
}
//********************************MAIN****************************************//
int main()
{
Matrix m0, m1, m2; //Matrices are 3x3;
// m0 <= m1 * m2
pthread_t id[9]; // 3x3 matrix multiplication requires 9 threads.
matrix_addr[0] = &m0; // the pointers to the matrices are stored here.
matrix_addr[1] = &m1;
matrix_addr[2] = &m2;
n = m = 0; // initialize the global variable
srand(time(NULL)); // seed rand()
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
{
m0.d[i][j] = 0; // m0 is being cleared for the output
m1.d[i][j] = rand()%10; // m1 and m2 are generated with rand()
m2.d[i][j] = rand()%10;
}
}
//display the input matrices
cout << "MATRIX 1:\n\n";
print (&m1);
cout << "\nMATRIX 2:\n\n";
print (&m2);
cout << "\nMATRIX 3:\n\n";
print (&m0);
for (int i = 0; i < SIZE*SIZE; i++) // run all the threads for calculating each output
{
m = i % SIZE;
n = i / SIZE;
cout << endl << "Going in to thread " << i << " with n = " << n << " and m = " << m;
pthread_create(&id[i], NULL, calcTerm, (void*) matrix_addr);
cout << endl << "Out of thread " << i ;
//pthread_join(id[i], NULL);
}
//pthread_cond_wait(&my_cond, &my_mutex);
cout << endl << endl;
print_result (&m0, &m1, &m2);
return 0;
}
It seems like the calcTerm thread does not take the correct pointers or something. It calculates gibberish values, but the final output at the end of main prints the same matrices I started off with.
Thanks again.