c - Initialize an array using openmpi once -


I'm trying to run some tests using OAPNP processing data, with metric) I now have some problems Running because the data ARR is being started every time and I do not know how to stop it from happening.

How can I use ANSI C, I can create a variable length array, can I use OPENmpi? I tried to make it static and global, but nothing

  #define NUM_THREADS 4 #define NUM_DATA 1000 static int * list = NULL; Int main (int argc, char * argv []) {int numprocs, rank, names; Four processor_name [MPI_MX_Processor_master]; Int N = NUM_DATA * NUM_DATA; Printf ("hi \ n"); Int i; If (list == faucet) {printf ("ho \ n"); List = malloc (n * sizeof (int)); (I = 0; i & lt; n; i ++) for {list [i] = rand ()% 1000; }} Int position; MPI_Init (& amp; argc, & argv); MPI_Comm_size (MPI_COMM_WORLD, & amp; numprocs); MPI_Comm_rank (MPI_COMM_WORLD, and Rank); MPI_Get_processor_name (processor_name, and naming); Printf ("% d on% d process% d \ n", rank, processor_name, number proxy); Clock_t start = clock (); Status = N / NUM_THREADS * Rank; Search (List, Status, N / NUM_THREADS * (Rank + 1)); Printf ("Time elapsed:% F seconds \ n", ((double) clock () - (double) start) / (double) CLOCKS_PER_SEC); Free (list); MPI_Finalize (); Return 0; }  

Perhaps the easiest way is to start the rank 0 process, while Other procedures block Once the initial work is done, then they have to start their work.

A basic example of calling your search function (NB: it is coded dry):

  define # NUM_THREADS # defined NUM_DATA 1000 int main (int argc , Char * argv []) {int * list; Int NanProx, Rank, Nemelan, I, N. Int Chanex, Offset; Four processor_name [MPI_MX_Processor_master]; N = NUM_DATA * NUM_DATA; MPI_Status stat; MPI_Init (& amp; argc, & argv); MPI_Comm_size (MPI_COMM_WORLD, & amp; numprocs); MPI_Comm_rank (MPI_COMM_WORLD, and Rank); MPI_Get_processor_name (processor_name, and naming); // Note you N% NUM_THREADS! = 0 will need to handle, but I'm ignoring it that chunksize for now = n / NUM_THREADS; If (Rank == 0) {// Think about this as a Master Process / Initiating Your Initiative in the List of Process = malloc (n * sizeof (int)); (I = 0; i & lt; n; i ++) for {list [i] = rand ()% 1000; } // Once ready, send a part to each slave process to work offset = Choices; {MPI Side (& amp; List [Offset], Chunxis, MPINDT, I, 0, MPICOMMWWLD) for I (i = 1; i & lt; numprocs; i ++); Offset + = select case} search (list, 0, choisex); // If you need some sort of feedback from slaves, then make a rec loop} else {// If you are not a master, then you are doing a slave process, so wait for the data to get list = malloc (Chunksize * sizeof (int)); MPI_Recv (List, Chunex, MPI_INT, 0, 0, MPI_COMM_WORLD, and State); // Now you can work on searching for your part (list, 0, choisex); // If you need to send some back master, then do it here} MPI_Finalize (); }  

Comments