Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "config.h"
00014
00015 #ifdef GS_SMART_GRIDSOLVE
00016 #include "gs_smart_task_graph.h"
00017 #include "gs_smart_mapping_graph.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 int gs_smart_next_permutation(int ** mapping_matrix, int number, int base, int nb_tasks){
00036 int mod;
00037 int multiple=number;
00038 int fin=0;
00039 int col_nb=0;
00040
00041 if(!mapping_matrix){
00042 ERRPRINTF("SMART: Error could not allocate memory to mapping matrix\n");
00043 return -1;
00044 }
00045
00046 while(col_nb<nb_tasks){
00047 if(multiple>=base&&col_nb<nb_tasks){
00048 mod = (multiple%base);
00049 mapping_matrix[mod][col_nb]=1;
00050 multiple=(int)multiple/base;
00051 col_nb++;
00052 }
00053 if(fin==1&&col_nb<nb_tasks){
00054 mapping_matrix[0][col_nb]=1;
00055 col_nb++;
00056 }
00057 else{
00058 if(multiple<base&&col_nb<nb_tasks){
00059 mapping_matrix[multiple][col_nb]=1;
00060 col_nb++;
00061 fin=1;
00062 }
00063 }
00064 }
00065 return 0;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 int gs_smart_zero_mapping_matrix(int **mapping_matrix, int nb_servers, int nb_tasks)
00084 {
00085 int i;
00086 if(!mapping_matrix) return -1;
00087
00088 if((nb_tasks<=0)||(nb_servers<=0)){
00089 ERRPRINTF("SMART: Number of tasks or servers is not greater zero\n");
00090 return -1;
00091 }
00092 int j;
00093 for( i = 0; i < nb_servers; i++){
00094 for( j = 0; j < nb_tasks; j++){
00095 mapping_matrix[i][j] = 0;
00096 }
00097 }
00098 return 0;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 int gs_smart_matrix_to_vec(int ** mapping_matrix, int nb_servers, int nb_tasks, int * mapping_vector){
00115 if(!mapping_matrix) return -1;
00116
00117 int i, j;
00118 for(i=0;i<nb_servers;i++){
00119 for(j=0;j<nb_tasks;j++){
00120 if(mapping_matrix[i][j]==1){
00121 mapping_vector[j]=i;
00122 }
00123 }
00124 }
00125
00126 return 0;
00127 }
00128
00129
00130 #endif