diff --git a/clustering.cpp b/Clustering.cpp similarity index 100% rename from clustering.cpp rename to Clustering.cpp diff --git a/clustering.h b/Clustering.h similarity index 100% rename from clustering.h rename to Clustering.h diff --git a/Parameters.h b/Parameters.h index ae062ee..70adc8c 100644 --- a/Parameters.h +++ b/Parameters.h @@ -1,8 +1,8 @@ #pragma once //* DEFINE ALL THE PARAMETERS HERE */ -#define iter 10 -#define VER 10 // width of lattice matrix. for ex 6*6 lattice +#define iter 1 +#define VER 64 // width of lattice matrix. for ex 6*6 lattice #define DIM 2 // dimension of lattice // here 2; square lattice #define latt_pc 1 // percentage of lattice points where atom exist #define upspin_pc 0.5 // percentage of upspin in lattice @@ -26,4 +26,4 @@ #define d " : " // used in push relabel -#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) \ No newline at end of file +#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) diff --git a/RFIM_2D_main.cpp b/RFIM_2D_main.cpp index 8b82423..eb182d8 100644 --- a/RFIM_2D_main.cpp +++ b/RFIM_2D_main.cpp @@ -7,15 +7,21 @@ //#define _HAS_ITERATOR_DEBUGGING 0 +#include #include "Headers.h" #include "Parameters.h" #include "Clustering.h" #include "PushRelabel.h" #include "LatticeStuff.h" + using namespace std; + +ofstream f; int main(void) { + f.open("log.dat",ios::app); + //Mat image(VER, VER, CV_8UC3); @@ -25,6 +31,7 @@ int main(void) { for (l = 0; l < iter; l++) { + f << "iter: " << l < +#include +#include +#include "Headers.h" +#include "Parameters.h" +#include "Clustering.h" +#include "PushRelabel.h" +#include "LatticeStuff.h" +#ifdef unix + #include +#endif +#define NUM_THREADS 1 + +using namespace std; + + +ofstream f; + +int randomizer(void){ + random_device rand_dev; + mt19937 generator(rand_dev()); + uniform_int_distribution distr(0,5000); + return distr(generator); +} +void *blowjob(void* thread_id) { + pthread_mutex_t mutex; + + long id = (long)thread_id; + string file_name = "log/log"; + file_name += to_string(id); + file_name = file_name + "_" + to_string(randomizer()) + ".dat"; + f.open(file_name,ios::app); + + cout << file_name << endl; + + time_t time_begin, time_end, time_1, time_2; + + long t1, t2, tdiff[iter] = { 0 }, l = 0, sum = 0, i, j, cap = 0, clusters = 0; + + for (l = 0; l < iter; l++) + { + f << "iter: " << l < > flow(V, vector(V, 0)) + , CapacityMat(V, vector(V, 0)) + , Exmat(N, vector(N, 0)) + , sqlat0(VER + 1, vector(VER + 1, 0)) + , sqlat1(VER + 1, vector(VER + 1, 0)); + + /* ==================== INITIALISING 1D VECTORS ================*/ + vector visited(V, 0), Wmat(N, 0), latt(N, 1), Bmat(N, 0), clusstats0(V / 2, 0), clusstats1(V / 2, 0); + + /* =========================== BETA MATRIX (Bmat)======================= */ + + //create_Bmat_bimodal(Bmat); // UNCOMMENT FOR BIMODAL DISTRIBUTION + create_Bmat_gaussian(Bmat); + cout << "Bmat created" << endl; + + /* ====================== CREATING EXISTANCE MATRIX (Exmat)============= */ + + create_Exmat(Exmat, latt); + cout << "Exmat created" << endl; + + /* ================= CREATING CAPACITY MATRIX (CapacityMat)============= */ + + create_CapacityMat(CapacityMat, Exmat); + cout << "created CapacityMatrix" << endl; + + /* =================== LOOP TO ITERATE OVER RANGE OF DELTA ============= */ + + for (int del = del_beg; del <= del_end; del += del_inc) + { + f << "del: " << del << endl; + //open + cout << "\ndEL: " << float(del) / 10 << tab; + + create_Wmat(Wmat, CapacityMat, Bmat, del); + + /* =========== AGUMENTING CAPACITY MATRIX WITH WMAT ============= */ + + create_Augumented_CapacityMat(Wmat, CapacityMat); + + t1 = time(&time_1); /* get current time;*/ + + /*================================================================================================*/ + /* ladies and gentlemen its honour to present you the most important stuff in this awesome code */ + /* ===================== CALLING PUSH RELABEL(CapacityMat)======================================= */ + + pushRelabel(CapacityMat, flow, 0, V - 1); + + /*====================================================================================*/ + t2 = time(&time_2); /* get current time;*/ + + /* ====================== CREATE RESIDUAL GRAPH ================== */ + create_Residual_graph(CapacityMat, flow); + + /*======================================================*/ + /*============ CLUSTERIZATION ======================= */ + /*======================================================*/ + + /* ================= DEPTH FIRST SEARCH ON FLOW ================== */ + dfs(flow, 0, visited); + + /* ============ CREATE AGUMENTED MATRIX AROUND LATTICE =========== */ + createAgumentedMatrix(sqlat0, sqlat1, visited); + + /* ====================== HK CLUSTER ALGO ================== */ + cluster(sqlat1, 1, clusstats1); + cluster(sqlat0, 0, clusstats0); + + /* ====================== PRINT CLUSTERS ================== */ + //printCluster(sqlat1, clusstats1); + //printCluster(sqlat0, clusstats0); + + /* ====================== COUNT CLUSTERS ================== */ + clusters = no_of_clusters(clusstats0, clusstats1); + cout << "clusters: " << clusters << "\n\n"; + f << "clusters: " << clusters << endl; + + tdiff[l] = t2 - t1; + sum += tdiff[l]; + + //re_init + for (i = 0; i < V; i++) + { + for (j = 0; j < V; j++) + { + + if (i < VER + 1 && j < VER + 1) + { + + sqlat0[i][j] = 0; + sqlat1[i][j] = 0; + } + + + flow[i][j] = 0; + } + if (i < V / 2) + { + + clusstats0[i] = 0; + clusstats1[i] = 0; + } + if (i < N) + { + + Wmat[i] = 0; + }visited[i] = 0; + + } + //close + } + + + flow.clear(); + CapacityMat.clear(); + Exmat.clear(); + visited.clear(); + Wmat.clear(); + sqlat0.clear(); + sqlat1.clear(); + clusstats0.clear(); + clusstats1.clear(); + f << endl; + + } + cout << "\n\n\nAVERAGE TIME for " << VER << " ver : " << sum / iter << endl; + + // print time req for each iter + for (l = 0; l < iter; l++) + { + cout << "-" << tdiff[l]; + } + + f.close(); + +} + +int main(int argc,char *argv[]){ + pid_t p = fork(); + pthread_t threads[NUM_THREADS]; + int iret; + // multiple blowjobs at the same time + for(int i = 0;i < NUM_THREADS;i++){ + + iret = pthread_create(&threads[i],NULL,blowjob,(void*)i); + + if (iret) { + cout << "Error:unable to create thread," << iret << endl; + exit(-1); + } + + } + + for(int i = 0;i < NUM_THREADS;i++){ + pthread_join(threads[i],NULL); + } + + // for deleting the executable file after running the program + //remove(argv[0]); + + + return 0; + +} \ No newline at end of file diff --git a/log.dat b/log.dat new file mode 100644 index 0000000..ec2b994 --- /dev/null +++ b/log.dat @@ -0,0 +1,252 @@ +iter: 0 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 1 +del: 14 +clusters: 1 +del: 16 +clusters: 6 +del: 18 +clusters: 7 +del: 20 +clusters: 8 +del: 22 +clusters: 15 +del: 24 +clusters: 15 +del: 26 +clusters: 15 +del: 28 +clusters: 14 +del: 30 +clusters: 16 +del: 32 +clusters: 14 +del: 34 +clusters: 14 +del: 36 +clusters: 16 +del: 38 +clusters: 16 +del: 40 +clusters: 22 + +iter: 1 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 1 +del: 14 +clusters: 2 +del: 16 +clusters: 4 +del: 18 +clusters: 6 +del: 20 +clusters: 7 +del: 22 +clusters: 10 +del: 24 +clusters: 11 +del: 26 +clusters: 12 +del: 28 +clusters: 13 +del: 30 +clusters: 17 +del: 32 +clusters: 24 +del: 34 +clusters: 23 +del: 36 +clusters: 23 +del: 38 +clusters: 23 +del: 40 +clusters: 25 + +iter: 0 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +iter: 0 +del: 0 +clusters: 1 +del: 2 +iter: 0 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 1 +del: 14 +clusters: 3 +del: 16 +clusters: 3 +del: 18 +clusters: 4 +del: 20 +clusters: 16 +del: 22 +clusters: 18 +del: 24 +clusters: 18 +del: 26 +clusters: 17 +del: 28 +clusters: 15 +del: 30 +clusters: 19 +del: 32 +clusters: 21 +del: 34 +clusters: 19 +del: 36 +clusters: 20 +del: 38 +clusters: 20 +del: 40 +clusters: 29 + +iter: 1 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 1 +del: 14 +clusters: 1 +del: 16 +clusters: 3 +del: 18 +clusters: 3 +del: 20 +clusters: 3 +del: 22 +clusters: 7 +del: 24 +clusters: 7 +del: 26 +clusters: 9 +del: 28 +clusters: 11 +del: 30 +clusters: 12 +del: 32 +clusters: 15 +del: 34 +clusters: 15 +del: 36 +clusters: 16 +del: 38 +clusters: 16 +del: 40 +clusters: 20 + +iter: 0 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 1 +del: 14 +clusters: 6 +del: 16 +clusters: 11 +del: 18 +clusters: 13 +del: 20 +clusters: 15 +del: 22 +clusters: 49 +del: 24 +clusters: 38 +del: 26 +clusters: 43 +del: 28 +iter: 0 +iter: 0 +del: 0 +del: 0 +clusters: 1 +del: 2 +clusters: 1 +del: 2 +clusters: 1 +del: 4 +clusters: 1 +del: 6 +clusters: 1 +del: 8 +clusters: 1 +del: 10 +clusters: 1 +del: 12 +clusters: 2 +del: 14 +clusters: 3 +del: 16 +clusters: 9 +del: 18 +clusters: 10 +del: 20 +clusters: 19 +del: 22 diff --git a/main b/main new file mode 100755 index 0000000..96d013b Binary files /dev/null and b/main differ diff --git a/make.sh b/make.sh new file mode 100755 index 0000000..f0ac9c2 --- /dev/null +++ b/make.sh @@ -0,0 +1,12 @@ + +#obj_file=(${1//./ }) + +if g++ --std=c++14 -Wall RFIM_2D_main.cpp LatticeStuff.cpp Clustering.cpp PushRelabel.cpp -o main ; then + echo '*************' + ./main + +else + exit +fi + +#rm build/$obj_file diff --git a/make_RFIM_2D_main_multi_core.sh b/make_RFIM_2D_main_multi_core.sh new file mode 100755 index 0000000..a758455 --- /dev/null +++ b/make_RFIM_2D_main_multi_core.sh @@ -0,0 +1,14 @@ + +#obj_file=(${1//./ }) + +if g++ --std=c++14 -Wall RFIM_2D_main_multi_core.cpp LatticeStuff.cpp Clustering.cpp PushRelabel.cpp -lpthread -o main ; then + echo '****** RUNNING MULTI CORE RFIM SIMULATION *******' + ./main + +else + echo ' XXXXX SOMETHING WENT WRONG XXXXX ' + echo ' XXXXX most probably your career decision ' + exit +fi + +#rm build/$obj_file