Ich versuche derzeit, ein C++ - Programm mit Pthreads.h für Multi-Thread-Matrix-Multiplikation zu schreiben.pthreads Multi-Thread-Matrix-Multiplikation
Ich versuche, die Fäden zu schaffen, wie
int numthreads = (matrix[0].size() * rsize2);//Calculates # of threads needed
pthread_t *threads;
threads = (pthread_t*)malloc(numthreads * sizeof(pthread_t));//Allocates memory for threads
int rc;
for (int mult = 0; mult < numthreads; mult++)//rsize2
{
struct mult_args args;
args.row = mult;
args.col = mult;
cout << "Creating thread # " << mult;
cout << endl;
rc = pthread_create(&threads[mult], 0, multiply(&args), 0);
}
Dieser erstellt dann Fäden folgt, dass meine Multiplikationsfunktion ausführen, die wie folgt codiert
void *multiply(int x, int y)
{
int oldprod = 0, prod = 0, sum = 0;
cout << "multiply";
for(int i = 0; i < rsize2; i++)//For each row in #ofrows in matrix 2
{
prod = matrix[x][i] * matrix2[i][y];//calculates the product
sum = oldprod + prod; //Running sum starting at 0 + first product
oldprod = prod; //Updates old product
}
Mein Fehler in meiner Multiplikationsfunktion liegt. Ich versuche, einen kompatiblen Weg zu finden, um eine x- und y-Koordinate für jeden Thread zu übergeben, so dass er genau weiß, welche Summe zu berechnen ist, aber ich bin mir nicht sicher, wie dies für die Funktion pthreads_create() akzeptabel ist .
Update: Ich weiß, dass ich eine Struktur zu verwenden, haben diese
struct mult_args {
int row;
int col;
};
zu erreichen, aber ich kann nicht die Multiplikationsfunktion erhalten die Struktur
Warum nicht 'std :: thread' an erster Stelle? – user0042
pthreads ist eine Voraussetzung für das Projekt – Zac
_pthreads ist eine Voraussetzung für das Projekt_ YAIT (noch ein inkompetenter Lehrer) –