0

I am a beginner for MPI coding. I want to have structs across multiple processes.

I have a struct for the count min sketch:

 typedef struct CM_type{
    long long count;
    int depth;
    int width;
    int ** counts;
    unsigned int *hasha, *hashb;
  } CM_type;

I wrote a function for initialization of this count min sketch.

std::vector<CM_type> CM_Init(int width, int depth, int seed)
{

     int j;
     prng_type * prng;
     prng=prng_Init(-abs(seed),2); 
     #pragma omp parallel shared (width, depth, prng) private(j)
     {
       
          //CM_type cm_loc;
          std::vector<CM_type> cm_loc;
          //std::vector<CM_type> cm_loc;
          cm_loc.depth=depth;
          cm_loc.width=width;
          cm_loc.count=0;
          cm_loc.counts=(int **)calloc(sizeof(int *),cm_loc.width);
          cm_loc.counts=(int *)calloc(sizeof(int), cm_loc.depth*cm_loc.width);
          //cm->total = 0;
          cm_loc.hasha=(unsigned int *)calloc(sizeof(unsigned int),cm_loc.depth);
          cm_loc.hashb=(unsigned int *)calloc(sizeof(unsigned int),cm_loc.depth);
          if (cm_loc.counts && cm_loc.hasha && cm_loc.hashb && cm_loc.counts[0])
          {
                for (j=0;j<depth;j++)
                {
                    #pragma omp critical
                    {
                        cm_loc.hasha[j]=prng_int(prng) & MOD;
                        cm_loc.hashb[j]=prng_int(prng) & MOD;
                        // pick the hash functions
                        cm_loc.counts[j]=(int *) cm_loc.counts[0]+(j*cm_loc.width);
                    }
                }
            }
          //else cm_loc = NULL;
          return cm_loc[0];
          
      }  
}   

My objective is to create local count min sketches across multiple processes and then initialize the local sketches independently. When I am running this code I am getting an error like this:

  error: 'class std::vector<CM_type>' has no member named 'depth'
           cm_loc.depth=depth;
                  ^~~~~
  error: 'class std::vector<CM_type>' has no member named 'width'
           cm_loc.width=width;

and so on. For all the structure members I am getting this error. I can give you any more information if required. Kindly help. Thank you.

Ashi
  • 61
  • 5
  • 2
    `cm_loc` is a **vector** so it doesn't indeed have any member named `depth` or `width`. Conversely `cm_loc[j]` does... – Gilles Nov 12 '20 at 05:39
  • 1
    Please edit your question to remove MPI (and, I expect, replace it with OpenMP), unless you do mean MPI (which your comment about "across multiple processes" might imply. If this is all an OpenMP code, then you mean "across multiple threads". Plus, since you show a compiler error, it is clearly not happening "when I am running this code". – Jim Cownie Nov 12 '20 at 10:28
  • 1
    @Gilles Yes you are right I tried to run the code by explicitly mentioning cm_loc[0] and at that time this eror is not coming. I want to create the structure cm_loc across all the processes locally and do a MPIAllreduce. Can you help me as to how can I create the local structures of the CM_type across all the processes? – Ashi Nov 12 '20 at 17:32
  • @JimCownie Yes I do mean across multiple processes and not multithreading only, My aim is to build the CM_type struct instants (cm_loc) across lmultiple processes where the processes can independently initialize their cm_loc and then do some work (which is another function) and then do a MPI_Allreduce(). – Ashi Nov 12 '20 at 17:37
  • For the MPI side of things, you may want to look at this: https://stackoverflow.com/questions/33618937/trouble-understanding-mpi-type-create-struct – jjramsey Nov 12 '20 at 17:54

1 Answers1

0

Please go and read almost anything on MPI. What you want to do is trivial, since the way that MPI works is that all main programs are entered independently and all of the MPI processes are separate, sharing no parts of their address space. (Unless you use more advanced features to achieve that). Therefore code like this (not compiled :-)) does what you want:

int main(int argc, char **argv) {
    myType var;   // one in each process!
    MPI_Init(...);
    .. operate on the local var ...
    MPI_Allreduce (passing var and so on);
}

There is no need for OpenMP, which merely complicates your example. Stating that your problem happens "when I am running this code", and then showing a compile-time error is also less than helpful.

As others have pointed out, your proximate problem is that your C++ code is broken aside from MPI or anything else!

Jim Cownie
  • 2,409
  • 1
  • 11
  • 20