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
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) queue.c -o queue
# $(CC) queue.c simulateFlux.c main.c -lm -lpthread -o main
./main < ../02400031.TXT

Binary file not shown.

View file

@ -21,20 +21,31 @@ int cptFile = 1;
double period = 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){
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = NULL; // change this for create empty
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData;
pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
pthread_t power;
pthread_create(&power , NULL, threadCalcul, (void *)&power);
pthread_t calcul;
pthread_create(&calcul , NULL, threadCalcul, (void *)&calcul);
pthread_exit(NULL);
}

View file

@ -30,18 +30,4 @@ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeB
else{
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 <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);

View file

@ -1,6 +1,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "queue.h"
/**
@ -12,7 +13,7 @@
*/
struct queue {
int charLen;
char * tabChar;
char* tabChar;
Pqueue pNextE;
};
@ -39,9 +40,8 @@ Pqueue queueCreateEmpty(){
*
* @param elem targeted element
* @param _charLen size of char array
* @return Pqueue
*/
Pqueue queueSetCharLen(Pqueue elem, int _charLen){
void queueSetCharLen(Pqueue elem, int _charLen){
assert(elem);
elem->charLen = _charLen;
}
@ -52,17 +52,27 @@ Pqueue queueSetCharLen(Pqueue elem, int _charLen){
* @param elem targeted element
* @param _charLen char array size
* @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(_tabChar);
elem->charLen = _charLen;
elem->tabChar = (char *) malloc(_charLen * sizeof(char));
elem->tabChar = calloc(_charLen , sizeof(char));
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 ************/
@ -115,12 +125,6 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
return new;
}
void setNextE(Pqueue elem , Pqueue next){
assert(elem);
assert(next);
elem -> pNextE = next;
}
/**
* @brief remove and free the last element of queue
*
@ -175,18 +179,17 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @param len the lenght of char array
* @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(str);
Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){
previous = tmp;
tmp = queueGetNextE(tmp);
Pqueue next = elem, previous = NULL;
while(next->pNextE != NULL){
previous = next;
next = queueGetNextE(next);
}
tmp = queueCreateE(len);
tmp->tabChar = str;
tmp->charLen = len;
return tmp;
previous = next;
next = queueCreateE(len,str);
queueSetNextE(previous,next);
}
/**
@ -196,12 +199,21 @@ Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){
*/
void queuePrintE(Pqueue 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){
printf("Next File : %s\n", next ->tabChar);
}
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;
//Constructors
Pqueue createE(int lenChar, const char* _tabChar);
Pqueue createEmpty();
Pqueue queueCreateE(int lenChar, const char* _tabChar);
Pqueue queueCreateEmpty();
//Getters
Pqueue getNextE(Pqueue elem);
Pqueue getNextE(Pqueue elem);
char * gettabChar(Pqueue elem);
Pqueue queueGetNextE(Pqueue elem);
int queueGetCharLen(Pqueue elem);
char* queueGetTabChar(Pqueue elem);
//Setters
void setCharLen(Pqueue elem , int _charLen);
void setTabChar(Pqueue elem , int _charLen , char *_tabChar);
void setNextE(Pqueue elem , Pqueue next);
void queueSetCharLen(Pqueue elem, int _charLen);
void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar);
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
Pqueue rmLastE(Pqueue elem);
Pqueue rmFrstE(Pqueue elem);
Pqueue nextDelFrst(Pqueue elem);
Pqueue nextDelFrst(Pqueue elem);
Pqueue queueRmLastE(Pqueue elem);
Pqueue queueRmFrstE(Pqueue elem);
Pqueue queueNextDelFrst(Pqueue elem);
//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 *fileName = "../RawDataFiles/RawData";
char *extension = ".csv";
char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile);
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 );
strcat( fileNameNumber, fileNumber );
strcpy( fullFileName, fileNameNumber );
strcat( fullFileName, extension );
return fullFileName;
}
@ -114,21 +114,21 @@ bool writeOneRawData(FILE *rawDataFile){
}
void *simulateFlux(void *vargp){
printf("start thread simul\n");
char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+");
Pqueue rawDataQueue = createE(strlen(fileName));
while(writeOneRawData(rawDataFile)){
if(cptData == nRow){
fclose(rawDataFile);
printf("in if\n");
cptData = 0;
cptFile++;
//create struct here
char *fileName = createNewRawDataFileName();
queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName));
//prepare next file now
fileName = createNewRawDataFileName();
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 cptFile;
char* convertIntegerToChar(int N);
char *convertIntegerToChar(int N);
bool writeOneRawData(FILE *f);
void *simulateFlux(void *vargp);