maj queue debug simul

This commit is contained in:
quentin.perret 2022-06-13 15:03:51 +02:00
parent b0fa82b06e
commit 75639d3c4a
10 changed files with 86 additions and 73 deletions

View file

@ -1,8 +1,7 @@
CC = gcc CC = gcc
all: all:
# rm powerData.csv
# $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main
$(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -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 simulateFlux.c main.c -lm -lpthread -o main
./main < ../02400031.TXT ./main < ../02400031.TXT

Binary file not shown.

View file

@ -21,20 +21,31 @@ int cptFile = 1;
double period = 0; double period = 0;
double invTimeBandWidth = 0; double invTimeBandWidth = 0;
void *threadCalcul(void *vargp){
printf("start thread calcul\n");
Pqueue rawDataQueue = firstRawDataQueue;
while(queueGetNextE(rawDataQueue) != NULL){
printf("wile calcul\n");
//pthread_mutex_lock(&mutex);
power(queueGetTabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth);
/*remove(queueGetTabChar(rawDataQueue));
rawDataQueue = queueRmFrstE(rawDataQueue);*/
//pthread_mutex_unlock(&mutex);
}
}
int main(int argc , char** argv){ int main(int argc , char** argv){
period = 1 / freqEch; period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period); invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = NULL; // change this for create empty firstRawDataQueue = queueCreateEmpty(); // 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_t calcul;
pthread_create(&power , NULL, threadCalcul, (void *)&power); pthread_create(&calcul , NULL, threadCalcul, (void *)&calcul);
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -30,18 +30,4 @@ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeB
else{ else{
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,5 +1,5 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
//bool power(int N , int M, double periode , double timeBandwidth); bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth);
void *threadCalcul(void *vargp); void *threadCalcul(void *vargp);

View file

@ -1,6 +1,7 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "queue.h" #include "queue.h"
/** /**
@ -12,7 +13,7 @@
*/ */
struct queue { struct queue {
int charLen; int charLen;
char * tabChar; char* tabChar;
Pqueue pNextE; Pqueue pNextE;
}; };
@ -39,9 +40,8 @@ Pqueue queueCreateEmpty(){
* *
* @param elem targeted element * @param elem targeted element
* @param _charLen size of char array * @param _charLen size of char array
* @return Pqueue
*/ */
Pqueue queueSetCharLen(Pqueue elem, int _charLen){ void queueSetCharLen(Pqueue elem, int _charLen){
assert(elem); assert(elem);
elem->charLen = _charLen; elem->charLen = _charLen;
} }
@ -52,17 +52,27 @@ Pqueue queueSetCharLen(Pqueue elem, int _charLen){
* @param elem targeted element * @param elem targeted element
* @param _charLen char array size * @param _charLen char array size
* @param _tabChar pointer to static char array * @param _tabChar pointer to static char array
* @return Pqueue
*/ */
Pqueue queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){ void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){
assert(elem); assert(elem);
assert(_tabChar); assert(_tabChar);
elem->charLen = _charLen; elem->charLen = _charLen;
elem->tabChar = (char *) malloc(_charLen * sizeof(char)); elem->tabChar = calloc(_charLen , sizeof(char));
for(int i = 0; i < _charLen; i++){ for(int i = 0; i < _charLen; i++){
new->tabChar[i] = _tabChar[i]; elem->tabChar[i] = _tabChar[i];
} }
} }
/**
* @brief set next pqueue element
*
* @param elem target element
* @param next next element
*/
void queueSetNextE(Pqueue elem , Pqueue next){
assert(elem);
assert(next);
elem -> pNextE = next;
}
/************ GETTER ************/ /************ GETTER ************/
@ -115,12 +125,6 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
return new; return new;
} }
void setNextE(Pqueue elem , Pqueue next){
assert(elem);
assert(next);
elem -> pNextE = next;
}
/** /**
* @brief remove and free the last element of queue * @brief remove and free the last element of queue
* *
@ -175,18 +179,17 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @param len the lenght of char array * @param len the lenght of char array
* @return Pqueue pointer to the last element * @return Pqueue pointer to the last element
*/ */
Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){ void queueAddLastQ(Pqueue elem, const char* str, int len){
assert(elem); assert(elem);
assert(str); assert(str);
Pqueue tmp = elem, previous = NULL; Pqueue next = elem, previous = NULL;
while(elem->pNextE != NULL){ while(next->pNextE != NULL){
previous = tmp; previous = next;
tmp = queueGetNextE(tmp); next = queueGetNextE(next);
} }
tmp = queueCreateE(len); previous = next;
tmp->tabChar = str; next = queueCreateE(len,str);
tmp->charLen = len; queueSetNextE(previous,next);
return tmp;
} }
/** /**
@ -196,12 +199,21 @@ Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){
*/ */
void queuePrintE(Pqueue elem){ void queuePrintE(Pqueue elem){
Pqueue next = queueGetNextE(elem); Pqueue next = queueGetNextE(elem);
printf("File Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen ); printf("\nFile Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen );
if(next != NULL){ if(next != NULL){
printf("Next File : %s\n", next ->tabChar); printf("Next File : %s\n", next ->tabChar);
} }
else{ else{
printf("No nextFile existing\n"); printf("No nextFile existing (null)\n");
}
}
void queuePrintWholeQ(Pqueue firstE){
queuePrintE(firstE);
Pqueue elem = firstE;
while(queueGetNextE(elem) != NULL){
elem = queueGetNextE(elem);
queuePrintE(elem);
} }
} }

View file

@ -1,28 +1,27 @@
typedef struct queue *Pqueue; typedef struct queue *Pqueue;
//Constructors //Constructors
Pqueue createE(int lenChar, const char* _tabChar); Pqueue queueCreateE(int lenChar, const char* _tabChar);
Pqueue createEmpty(); Pqueue queueCreateEmpty();
//Getters //Getters
Pqueue getNextE(Pqueue elem); Pqueue queueGetNextE(Pqueue elem);
Pqueue getNextE(Pqueue elem); int queueGetCharLen(Pqueue elem);
char * gettabChar(Pqueue elem); char* queueGetTabChar(Pqueue elem);
//Setters //Setters
void setCharLen(Pqueue elem , int _charLen); void queueSetCharLen(Pqueue elem, int _charLen);
void setTabChar(Pqueue elem , int _charLen , char *_tabChar); void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar);
void setNextE(Pqueue elem , Pqueue next); void queueSetNextE(Pqueue elem , Pqueue next);
Pqueue addLastQ(Pqueue elem, const char* str, int len); void queueAddLastQ(Pqueue elem, const char* str, int len);
//Removers //Removers
Pqueue rmLastE(Pqueue elem); Pqueue queueRmLastE(Pqueue elem);
Pqueue rmFrstE(Pqueue elem); Pqueue queueRmFrstE(Pqueue elem);
Pqueue queueNextDelFrst(Pqueue elem);
Pqueue nextDelFrst(Pqueue elem);
Pqueue nextDelFrst(Pqueue elem);
//print function //print function
void printE(Pqueue elem); void queuePrintE(Pqueue elem);
void queuePrintWholeQ(Pqueue firstE);

6
Code-C/rmRawData.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
cd ../RawDataFiles
for i in *
do
rm $i
done

View file

@ -30,18 +30,18 @@ char* convertIntegerToChar(int N)
char *createNewRawDataFileName(){ char *createNewRawDataFileName(){
char *fileName = "../RawDataFiles/RawData"; char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv"; char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile); char *fileNumber = convertIntegerToChar(cptFile);
char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; char fileNameNumber[strlen(fileName)+strlen(fileNumber)];
char *fullFileName = malloc( (strlen(fileNameNumber)+strlen(extension)) * sizeof(char*) ); char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*));
strcpy( fileNameNumber, fileName ); strcpy( fileNameNumber, fileName );
strcat( fileNameNumber, fileNumber ); strcat( fileNameNumber, fileNumber );
strcpy( fullFileName, fileNameNumber ); strcpy( fullFileName, fileNameNumber );
strcat( fullFileName, extension ); strcat( fullFileName, extension );
return fullFileName; return fullFileName;
} }
@ -114,21 +114,21 @@ bool writeOneRawData(FILE *rawDataFile){
} }
void *simulateFlux(void *vargp){ void *simulateFlux(void *vargp){
printf("start thread simul\n");
char *fileName = createNewRawDataFileName(); char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
Pqueue rawDataQueue = createE(strlen(fileName));
while(writeOneRawData(rawDataFile)){ while(writeOneRawData(rawDataFile)){
if(cptData == nRow){ if(cptData == nRow){
fclose(rawDataFile); printf("in if\n");
cptData = 0; cptData = 0;
cptFile++; cptFile++;
//create struct here //create struct here
char *fileName = createNewRawDataFileName(); queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName));
//prepare next file now
fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName));
printE(rawDataQueue);
} }
} }
} }

View file

@ -16,6 +16,6 @@ typedef struct {
extern int cptData; extern int cptData;
extern int cptFile; extern int cptFile;
char* convertIntegerToChar(int N); char *convertIntegerToChar(int N);
bool writeOneRawData(FILE *f); bool writeOneRawData(FILE *f);
void *simulateFlux(void *vargp); void *simulateFlux(void *vargp);