マスタワーカ形式のプログラムをVC++で…
Posted: 2010年1月10日(日) 01:38
これは、マスタワーカ形式で記述したCのマンデルブロ集合描画プログラムなのですが、このプログラムをVC++で動かすにはどうすればいいでしょうか。わかる方いらっしゃいましたら、教えていただけないでしょうか。
#include "common.h"
#include "common.c"
#include "container.h"
#include "container.c"
#define STR_MAX 256
#define REAL_MIN -2
#define REAL_MAX 0.5
#define IMAG_MIN -1.25
#define IMAG_MAX 1.25
#define CAMBUS_WIDTH 320
#define CAMBUS_HEIGHT 320
#define REAL_SCALE ((REAL_MAX - REAL_MIN) / CAMBUS_WIDTH)
#define IMAG_SCALE ((IMAG_MAX - IMAG_MIN) / CAMBUS_HEIGHT)
typedef struct thread_arg_t
{
int32_t thread_id;
struct cambus_t *cambus;
struct jobque_t *jobque;
pthread_t pthread;
}thread_arg_t;
typedef struct cambus_t
{
int32_t width;
int32_t height;
int32_t iter_max;
int32_t *buf;
}cambus_t;
typedef struct jobque_t
{
int32_t index;
int32_t job_num;
struct job_t *jobs;
pthread_mutex_t mutex;
}jobque_t;
typedef struct job_t
{
int32_t id;
int32_t x;
int32_t y;
int32_t width;
int32_t height;
}job_t;
void* agent(void *arg);
int32_t calc_point(double cx, double cy, int32_t iter_max);
job_t* jobque_pop(jobque_t *jobque);
void print_cambus(cambus_t *cambus);
int main(int argc, char **argv)
{
cambus_t *cambus;
jobque_t *jobque;
thread_arg_t *thread_args;
int32_t thread_id, thread_num, job_num, iter_max, print_flag, i;
double t1, t2;
if(argc < 5)
{
errn("usage : %s thread_num job_num iter_max print_flag", argv[0]);
error();
}
thread_num = atoi(argv[1]);
job_num = atoi(argv[2]);
iter_max = atoi(argv[3]);
print_flag = atoi(argv[4]);
if(CAMBUS_HEIGHT % job_num != 0)
{
errn("CAMBUS_HEIGHT % job_num != 0");
error();
}
cambus = (cambus_t*)my_malloc(sizeof(cambus_t));
cambus->width = CAMBUS_WIDTH;
cambus->height = CAMBUS_HEIGHT;
cambus->iter_max = iter_max;
cambus->buf = (int32_t*)my_malloc(cambus->width * cambus->height * sizeof(int32_t));
jobque = (jobque_t*)my_malloc(sizeof(jobque_t));
jobque->index = 0;
jobque->job_num = job_num;
jobque->jobs = (job_t*)my_malloc(job_num * sizeof(job_t));
for(i = 0; i < job_num; i++)
{
jobque->jobs.id = i;
jobque->jobs.x = 0;
jobque->jobs.y = cambus->height / job_num * i;
jobque->jobs.width = cambus->width;
jobque->jobs.height = cambus->height / job_num;
}
pthread_mutex_init(&jobque->mutex, NULL);
t1 = get_time();
thread_args = (thread_arg_t*)my_malloc(thread_num * sizeof(thread_arg_t));
for(thread_id = 0; thread_id < thread_num; thread_id++)
{
thread_args[thread_id].thread_id = thread_id;
thread_args[thread_id].cambus = cambus;
thread_args[thread_id].jobque = jobque;
pthread_create(&thread_args[thread_id].pthread, NULL, agent, &thread_args[thread_id]);
}
for(thread_id = 0; thread_id < thread_num; thread_id++)
{
pthread_join(thread_args[thread_id].pthread, NULL);
}
t2 = get_time();
errn("%lf", t2 - t1);
my_free(thread_args);
if(print_flag)
{
print_cambus(cambus);
}
my_free(jobque->jobs);
my_free(jobque);
my_free(cambus->buf);
my_free(cambus);
return 0;
}
etc…
#include "common.h"
#include "common.c"
#include "container.h"
#include "container.c"
#define STR_MAX 256
#define REAL_MIN -2
#define REAL_MAX 0.5
#define IMAG_MIN -1.25
#define IMAG_MAX 1.25
#define CAMBUS_WIDTH 320
#define CAMBUS_HEIGHT 320
#define REAL_SCALE ((REAL_MAX - REAL_MIN) / CAMBUS_WIDTH)
#define IMAG_SCALE ((IMAG_MAX - IMAG_MIN) / CAMBUS_HEIGHT)
typedef struct thread_arg_t
{
int32_t thread_id;
struct cambus_t *cambus;
struct jobque_t *jobque;
pthread_t pthread;
}thread_arg_t;
typedef struct cambus_t
{
int32_t width;
int32_t height;
int32_t iter_max;
int32_t *buf;
}cambus_t;
typedef struct jobque_t
{
int32_t index;
int32_t job_num;
struct job_t *jobs;
pthread_mutex_t mutex;
}jobque_t;
typedef struct job_t
{
int32_t id;
int32_t x;
int32_t y;
int32_t width;
int32_t height;
}job_t;
void* agent(void *arg);
int32_t calc_point(double cx, double cy, int32_t iter_max);
job_t* jobque_pop(jobque_t *jobque);
void print_cambus(cambus_t *cambus);
int main(int argc, char **argv)
{
cambus_t *cambus;
jobque_t *jobque;
thread_arg_t *thread_args;
int32_t thread_id, thread_num, job_num, iter_max, print_flag, i;
double t1, t2;
if(argc < 5)
{
errn("usage : %s thread_num job_num iter_max print_flag", argv[0]);
error();
}
thread_num = atoi(argv[1]);
job_num = atoi(argv[2]);
iter_max = atoi(argv[3]);
print_flag = atoi(argv[4]);
if(CAMBUS_HEIGHT % job_num != 0)
{
errn("CAMBUS_HEIGHT % job_num != 0");
error();
}
cambus = (cambus_t*)my_malloc(sizeof(cambus_t));
cambus->width = CAMBUS_WIDTH;
cambus->height = CAMBUS_HEIGHT;
cambus->iter_max = iter_max;
cambus->buf = (int32_t*)my_malloc(cambus->width * cambus->height * sizeof(int32_t));
jobque = (jobque_t*)my_malloc(sizeof(jobque_t));
jobque->index = 0;
jobque->job_num = job_num;
jobque->jobs = (job_t*)my_malloc(job_num * sizeof(job_t));
for(i = 0; i < job_num; i++)
{
jobque->jobs.id = i;
jobque->jobs.x = 0;
jobque->jobs.y = cambus->height / job_num * i;
jobque->jobs.width = cambus->width;
jobque->jobs.height = cambus->height / job_num;
}
pthread_mutex_init(&jobque->mutex, NULL);
t1 = get_time();
thread_args = (thread_arg_t*)my_malloc(thread_num * sizeof(thread_arg_t));
for(thread_id = 0; thread_id < thread_num; thread_id++)
{
thread_args[thread_id].thread_id = thread_id;
thread_args[thread_id].cambus = cambus;
thread_args[thread_id].jobque = jobque;
pthread_create(&thread_args[thread_id].pthread, NULL, agent, &thread_args[thread_id]);
}
for(thread_id = 0; thread_id < thread_num; thread_id++)
{
pthread_join(thread_args[thread_id].pthread, NULL);
}
t2 = get_time();
errn("%lf", t2 - t1);
my_free(thread_args);
if(print_flag)
{
print_cambus(cambus);
}
my_free(jobque->jobs);
my_free(jobque);
my_free(cambus->buf);
my_free(cambus);
return 0;
}
etc…