以下用Eclipse luna 在OS X 10.10下编译通过。
#include "MatrixMultiplication.h"
void* Hello(void* rank);
int main() {
long thread;
pthread_t* thread_handles;
thread_handles = reinterpret_cast<pthread_t*>(malloc(
thread_count * sizeof(pthread_t)));
for (thread = 0; thread < thread_count; thread++) {
pthread_create(&thread_handles[thread], NULL, Hello, (void*) thread);
}
printf("Hello world from the main thread.\n");
for (thread = 0; thread < thread_count; thread++) {
pthread_join(thread_handles[thread], NULL);
}
free(thread_handles);
GenerateMatrix();
printf("\nBegin to multiply two matrix...\n");
MultiplyMatrix();
return 0;
}
void* Hello(void* rank) {
long my_rank = reinterpret_cast<long>(rank);
printf("Hello world from %ld thread of %ld.\n", my_rank, thread_count);
return NULL;
}
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <fstream>
#include <sys/time.h>
#define MATRIX_COLUMN 1000
#define MATRIX_ROW 1000
using namespace std;
long thread_count = 2; //Actually, the number of the threads is thread_count square.
int matrix_a[MATRIX_ROW][MATRIX_COLUMN];
int matrix_b[MATRIX_ROW][MATRIX_COLUMN];
int serial_result_matrix[MATRIX_ROW][MATRIX_COLUMN];
int parallel_result_matrix[MATRIX