Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
boa noite ..
estou tendo problemas com um script aqui.. esta dando alguns erros que n consigo resolver.. vou postar o codigo e se alguem souber me diga o q esta errado.
código onde esta os erros
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "tempo.h"
#define tamanho 10000;
#define p 10;
int vet[tamanho];
int vet_1[tamanho];
int maaa[tamanho][tamanho];
void inicializa_vetor();
void *soma_vetor(void *arg);
pthread_mutex_t m;
int (int argc, char *argv[])
{
tempo1();
pthread_t u[p];
int x[p];
int cc;
int ll;
for (cc=0;cc<tamanho;cc++){
for(ll=0; ll<tamanho;ll++){
m[cc][ll] = rand()+1;
}
}
int ee;
int dd;
for (dd=0;dd<tamanho;dd++){
v[dd] = rand()+8;
}
for (ee=0;ee<tamanho;ee++){
v_1[ee]= ee;
}
pthread_mutex_init(&m,NULL);
int qq;
for (qq=0; qq < p; qq ++){
x[qq] = qq*1000;
pthread_create(&u[qq], NULL, soma_vetor, (void *)&x[qq]);
}
for (q=0; q < p; q ++){
pthread_join(u[q], NULL);
}
tempo2();
tempoFinal("mili segundos", argv[0], MSGLOG);
}{
int w, pos = *((int*)arg);
pthread_t pid = pthread_self();
int a;
int b;
for (a=pos; a < (1000+pos); a++){
for (b=pos;b<(1000+pos);b++){
v_1[a] = v_1[a] + v[b] * m[a][b];
}
}
}
estes são os erros mostrados
matriz_dez_thread.c:10: error: expected ‘]’ before ‘;’ token
matriz_dez_thread.c:11: error: expected ‘]’ before ‘;’ token
matriz_dez_thread.c:12: error: expected ‘]’ before ‘;’ token
matriz_dez_thread.c:12: error: expected identifier or ‘(’ before ‘]’ token
matriz_dez_thread.c:19: error: expected identifier or ‘(’ before ‘int’
matriz_dez_thread.c: In function ‘soma_vetor’:
matriz_dez_thread.c:93: error: ‘v_1’ undeclared (first use in this function)
matriz_dez_thread.c:93: error: (Each undeclared identifier is reported only once
matriz_dez_thread.c:93: error: for each function it appears in.)
matriz_dez_thread.c:93: error: ‘v’ undeclared (first use in this function)
matriz_dez_thread.c:93: error: subscripted value is neither array nor pointer
este códido é do tempo.h que eu faço o include
#include <sys/time.h>
struct timeval t1, t2;
struct timezone tz1, tz2;
char MSGLOG[200]; // armazena o log no arquivo
void tempo1() {
gettimeofday(&t1, &tz1);
}
void tempo2() {
gettimeofday(&t2, &tz2);
}
void tempoFinal(const char medida, char nomeArquivo, char *msglog) {
char tempo[50];
long int micro = (((t2.tv_sec*1000000)+t2.tv_usec) - ((t1.tv_sec*1000000)+t1.tv_usec));
if (strcmp(medida,"")==0)
sprintf(tempo,"Tempo total= %.2f s", micro / 1000000.0);
if (strcmp(medida,"micro segundos")==0)
sprintf(tempo,"Tempo total= %ld us", micro);
if (strcmp(medida,"mili segundos")==0)
sprintf(tempo,"Tempo total= %.2f ms", micro / 1000.0);
if (strcmp(medida,"segundos")==0)
sprintf(tempo,"Tempo total= %.2f s", micro / 1000000.0);
if (strcmp(medida,"minutos")==0)
sprintf(tempo,"Tempo total= %.2f min", (micro / 1000000.0) / 60);
if (strcmp(medida,"horas")==0)
sprintf(tempo,"Tempo total= %.2f horas", ((micro / 1000000.0) / 60)) / 60;
printf("\n...: %s\n",tempo);
if ((nomeArquivo) != NULL) {
gravaArquivo(nomeArquivo, msglog, tempo);
}
}
int gravaArquivo(char nomeArquivo, char msglog, char *tempo) {
char nomearq[100];
FILE *fp;
sprintf(nomearq,"%s.log",nomeArquivo);
if ((fp = fopen((char *)nomearq, "a+t")) == NULL) {
// Arquivo nao existe
if ((fp = fopen(nomearq, "wt")) == NULL) {
// Erro de criacao do arquivo
perror("Erro");
}
}
fprintf(fp,"%s %s\n",msglog,tempo);
fclose(fp);
}Carregando comentários...