I'm supposed to use C++ and the PThread API (can't use the Win 32 API). I'm supposed to take a matrix and use a bunch of threads to solve each part of the matrix, or each calculation. I'm to have bunch of threads or process, can't recall which. Anyway, I need them to solve each part of the matrix, but only do one calculation per thread.

I'm to read in two text files, each containing a matrix, and then use a bunch of threads, one per calculation, to calculate the new matrix and then am to write the new matrix to the screen.

I have little idea how to read in each matrix.

The main thread, yeah, it's threads, is supposed to initalize the matrixes, with the values of the text files I think.

Another problem is that I'm not allowed to assume the size of the matrices, yet I'll need to know their sizes somehow in order to do the calculations correctly. I already have the formula for the calculations, and, once this gets to work, should be able to run it for each thread.

I think I need to somehow tell it to add some int variable that keeps track of the X size, and the y size. It need not be a N by N matrix that's read in. However, I'm going to assume that it has the same number of elements in each row (or else I'm doomed and I don't think it'd be a proper matrix if it did that anyway). I can tell it to increase the x size, but only for the first row and only until it reaches a new line, and that's another thing I'm confused about what to do.

For instance:

1 2 3 4

Should have a size of 4

However, I don't want it, if it's counting spaces, to see five spaces and mistakenly assume a size of 5.

Also, I don't know how to tell it if somehow the input file might be

1 2 3 4

to not suddenly assume 8 items are there now.

First off, how do I get it to read it in and count how many numbers are in a row and how many columns there are?

Code:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

iostream reader, reader2;

int main(int var, char* args)
{


reader(args[1]);

int rows = 0;

// need to read in till it reach a new line character.  Need to also increment 
// rows every time a space is reached, but not to keep incrementing if there happens to be two // or more spaces in the break.  




}
I'm trying to figure out how to make sure it can read in the info at the right time, as it doesn't say what to do with it, other than print it out after the calculations have been made.