00001 #include "ParFUM.h"
00002 #include "ParFUM_internals.h"
00003 #include "MsaHashtable.h"
00004
00005 using namespace MSA;
00006
00007 void operator+=(Hashtuple &t, const Hashnode &n)
00008 {
00009 t.vec->push_back(n);
00010 }
00011
00012 MsaHashtable::Add MsaHashtable::getInitialAdd()
00013 {
00014 if(initHandleGiven)
00015 throw MSA_InvalidHandle();
00016
00017 initHandleGiven = true;
00018 return Add(&this->msa);
00019 }
00020
00021 MsaHashtable::Add MsaHashtable::Read::syncToAdd()
00022 {
00023 syncDone();
00024 return Add(msa);
00025 }
00026
00027 MsaHashtable::Read MsaHashtable::Add::syncToRead()
00028 {
00029 syncDone();
00030 return Read(msa);
00031 }
00032
00033 void MsaHashtable::Read::print()
00034 {
00035 char str[100];
00036 for(int i=0; i < msa->length(); i++) {
00037 const Hashtuple &t = get(i);
00038 for(int j=0;j<t.vec->size();j++){
00039 Hashnode &tuple = (*t.vec)[j];
00040 printf("ghost element chunk %d element %d index %d tuple < %s>\n",
00041 tuple.chunk, tuple.elementNo, i,
00042 tuple.nodes.toString(tuple.numnodes,str));
00043 }
00044 }
00045 }
00046
00047 int MsaHashtable::Add::addTuple(int *tuple,int nodesPerTuple,int chunk,int elementNo)
00048 {
00049 int slots = msa->length();
00050
00051
00052
00053 for(int i=0;i<nodesPerTuple-1;i++){
00054 for(int j=i+1;j<nodesPerTuple;j++){
00055 if(tuple[j] < tuple[i]){
00056 int t = tuple[j];
00057 tuple[j] = tuple[i];
00058 tuple[i] = t;
00059 }
00060 }
00061 }
00062
00063
00064 CmiUInt8 sum = 0;
00065 for(int i=0;i<nodesPerTuple;i++){
00066 sum = sum*slots + tuple[i];
00067 }
00068 int index = (int )(sum %(long )slots);
00069 Hashnode entry(nodesPerTuple,chunk,elementNo,tuple);
00070
00071 accumulate(index) += entry;
00072 char str[100];
00073 DEBUG(printf("[%d] adding tuple %s element %d to index %d \n",chunk,entry.nodes.toString(nodesPerTuple,str),elementNo,index));
00074 return index;
00075 }
00076