我想寫一個程序,應該使用線程乘以矩陣。
我應該用一個線程中的隨機數填充矩陣。 我正在編譯g ++並使用PTHREADS。我還創建了一個結構,將數據從我的命令行輸入傳遞給線程,以便它可以生成隨機數字矩陣。兩個矩陣的大小也在命令行中傳遞。乘法矩陣:錯誤:預期初始表達式'結構'之前
我一直得到:main.cpp中:7:錯誤:預期 '結構' 我的代碼@行之前基本表達式7 =:
struct a{
int Arow;
int Acol;
int low;
int high;
};
我inpust是:
兩個矩陣的大小( 4個參數) 其中o產生之間的隨機數的高和低範圍。
完整代碼:
[headers]
using namespace std;
void *matrixACreate(struct *);
void *status;
int main(int argc, char * argv[])
{
int Arow = atoi(argv[1]); // Matrix A
int Acol = atoi(argv[2]); // WxX
int Brow = atoi(argv[3]); // Matrix B
int Bcol = atoi(argv[4]); // XxZ,
int low = atoi(argv[5]); // Range low
int high = atoi(argv[6]);
struct a{
int Arow; // Matrix A
int Acol; // WxX
int low; // Range low
int high;
};
pthread_t matrixAthread;
//pthread_t matrixBthread;
pthread_t runner;
int error, retValue;
if (Acol != Brow)
{
cout << " This matrix cannot be multiplied. FAIL" << endl;
return 0;
}
error = pthread_create(&matrixAthread, NULL, matrixACreate, struct *a);
//error = pthread_create(&matrixAthread, NULL, matrixBCreate, sendB);
retValue = pthread_join(matrixAthread, &status);
//retValue = pthread_join(matrixBthread, &status);
return 0;
}
void matrixACreate(struct * a)
{
struct a *data = (struct a *) malloc(sizeof(struct a));
data->Arow = Arow;
data->Acol = Acol;
data->low = low;
data->high = high;
int range = ((high - low) + 1);
cout << Arow << endl<< Acol << endl;
}// just trying to print to see if I am in the thread
向我們展示您的結構之前的代碼*。 – Erik 2011-03-07 22:31:55
當編譯器說錯誤在第7行時;這意味着直到第7行才能理解代碼。有時,很多時候,錯誤是在1或2行之前......但代碼仍然有意義。仔細觀察第4,5行,** 6 **和7. – pmg 2011-03-07 22:35:21
這可以通過在不屬於它的位置放一個分號來實現,但需要看到更完整的代碼纔能有任何想法。 – AJG85 2011-03-07 22:37:29