prepare power thread

This commit is contained in:
quentin.perret 2022-06-10 17:22:01 +02:00
parent 2e7253c43c
commit 4d19b6539e
12 changed files with 51 additions and 32 deletions

View file

@ -3,6 +3,6 @@ CC = gcc
all: all:
# rm powerData.csv # rm powerData.csv
# $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main # $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main
$(CC) queue.c simulateFlux.c main.c -lpthread -o main $(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main
# $(CC) queue.c -o queue # $(CC) queue.c -o queue
./main < ../02400031.TXT ./main < ../02400031.TXT

View file

@ -38,14 +38,3 @@ void writePowerData(double powerArray[], int nCol){
fclose(f); fclose(f);
} }
void threadCalcul(){
while(stopFlag == false){
if(rawDataWriteFlag){
pthread_mutex_lock(&mutex);
while(power(nRow,nCol,period,timeBandwidth) == false){}
pthread_mutex_unlock(&mutex);
rawDataWriteFlag = true;
delay(10);
}
}
}

View file

@ -3,7 +3,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
bool writeFlag = 0;
void clearRawData(int N); void clearRawData(int N);
void writePowerData(double a[], int N); void writePowerData(double a[], int N);

View file

@ -13,7 +13,7 @@ long **get(int N, int M) /* Allocate the array */
return array; return array;
} }
void fillArrayWithRawData(long** p, int N, int M) { void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
int i, j; int i, j;
char *buffer; char *buffer;
@ -21,7 +21,7 @@ void fillArrayWithRawData(long** p, int N, int M) {
buffer = (char *)malloc(bufsize * sizeof(char)); buffer = (char *)malloc(bufsize * sizeof(char));
char* token; char* token;
FILE *f = fopen("rawData.csv","r"); FILE *f = fopen(rawDataFileName,"r");
for(i = 0 ; i < N ; i++){ for(i = 0 ; i < N ; i++){
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
//printf("buffer : %s token : ",buffer); //printf("buffer : %s token : ",buffer);
@ -35,6 +35,7 @@ void fillArrayWithRawData(long** p, int N, int M) {
} }
//printf("\n\n"); //printf("\n\n");
} }
fclose(f);
} }
/** /**
* @brief print all the element of a bidimensionnal array p of shape : N x M * @brief print all the element of a bidimensionnal array p of shape : N x M
@ -71,10 +72,10 @@ void freeArray(long **p, int N) {
free(p); free(p);
} }
long **getRawDataArray(int N , int M){ long **getRawDataArray(char* rawDataFileName , int N , int M){
long **p; long **p;
p = get(N, M); p = get(N, M);
fillRawData(p ,N, M); fillArrayWithRawData(rawDataFileName,p ,N, M);
//printf("before test\n"); //printf("before test\n");
if(checkArrayFullyFill(p,N,M)==0){ if(checkArrayFullyFill(p,N,M)==0){
//printf("after test 0\n"); //printf("after test 0\n");

View file

@ -5,7 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
long **getRawDataArray(); long **getRawDataArray(char *rawDataFileName, int N , int M);
void printArrayData(long** p, int N, int M); void printArrayData(long** p, int N, int M);
void freeArray(long **p, int N); void freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N , int M); bool checkArrayFullyFill(long **p, int N , int M);

View file

@ -6,6 +6,9 @@ extern int nRow;
extern int nCol; extern int nCol;
extern double freqEch; extern double freqEch;
extern double period;
extern double invTimeBandWidth;
extern int selectionCaptors[]; extern int selectionCaptors[];
extern int sizeSelectionArray; extern int sizeSelectionArray;

Binary file not shown.

View file

@ -10,18 +10,31 @@ int nRow = 100000;
int nCol = 9; int nCol = 9;
double freqEch = 250; double freqEch = 250;
Pqueue firstRawDataQueue = NULL; Pqueue firstRawDataQueue;
int selectionCaptors[] = {1,2,3,4,5,6,7,8}; int selectionCaptors[] = {1,2,3,4,5,6,7,8};
int sizeSelectionArray = 8; int sizeSelectionArray = 8;
int cptData = 0;
int cptFile = 1;
double period = 0;
double invTimeBandWidth = 0;
int main(int argc , char** argv){ int main(int argc , char** argv){
double period = 1 / freqEch; period = 1 / freqEch;
double invTimeBandWidth = 1 /(nRow * period); invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = NULL; // change this for create empty
pthread_t rawData; pthread_t rawData;
pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData); pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
pthread_t power;
pthread_create(&power , NULL, threadCalcul, (void *)&power);
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -1,6 +1,8 @@
#include "power.h" #include "power.h"
#include "getArray.h" #include "getArray.h"
#include "fileGestion.h" #include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){ void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
for(int i = 0; i < M-1; i++){ for(int i = 0; i < M-1; i++){
@ -16,8 +18,8 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri
//printf("%f\n", powerArray[i]); //printf("%f\n", powerArray[i]);
} }
} }
bool power(int N , int M, double periode , double invTimeBandwidth){ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(N, M); long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8]; double pw[8];
if(p !=NULL){ if(p !=NULL){
powerCalculation(p,pw,N,M,periode,invTimeBandwidth); powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
@ -29,3 +31,17 @@ bool power(int N , int M, double periode , double invTimeBandwidth){
return false; return false;
} }
} }
void *threadCalcul(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
printf("print in power of first eleme in queue : \n");
printE(firstRawDataQueue);
while(rawDataQueue == NULL || getNextE(rawDataQueue) != NULL){
//pthread_mutex_lock(&mutex);
while(power(gettabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth) == false){
remove(gettabChar(rawDataQueue));
rawDataQueue = rmFrstE(rawDataQueue);
}
//pthread_mutex_unlock(&mutex);
//delay(10);
}
}

View file

@ -1,4 +1,5 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
int power(int N , int M, double periode , double timeBandwidth); //bool power(int N , int M, double periode , double timeBandwidth);
void *threadCalcul(void *vargp);

View file

@ -2,8 +2,6 @@
#include "initialParameters.h" #include "initialParameters.h"
#include "queue.h" #include "queue.h"
int cptData = 0;
int cptFile = 1;
char* convertIntegerToChar(int N) char* convertIntegerToChar(int N)
{ {
@ -119,9 +117,6 @@ void *simulateFlux(void *vargp){
char *fileName = createNewRawDataFileName(); char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
Pqueue rawDataQueue = createE(strlen(fileName)); Pqueue rawDataQueue = createE(strlen(fileName));
setTabChar(rawDataQueue , strlen(fileName) , fileName);
firstRawDataQueue = rawDataQueue;
printE(rawDataQueue);
while(writeOneRawData(rawDataFile)){ while(writeOneRawData(rawDataFile)){
if(cptData == nRow){ if(cptData == nRow){
@ -132,10 +127,8 @@ void *simulateFlux(void *vargp){
char *fileName = createNewRawDataFileName(); char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName)); rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName));
printE(rawDataQueue); printE(rawDataQueue);
} }
} }
printf("\n");
printE(firstRawDataQueue);
} }

View file

@ -13,5 +13,9 @@ typedef struct {
uint8_t octet4; uint8_t octet4;
} quartet; } quartet;
extern int cptData;
extern int cptFile;
char* convertIntegerToChar(int N);
bool writeOneRawData(FILE *f); bool writeOneRawData(FILE *f);
void *simulateFlux(void *vargp); void *simulateFlux(void *vargp);