Click here to Skip to main content
15,884,472 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionImage display problem in listcontrol Pin
tianzhili439925-Apr-19 16:50
tianzhili439925-Apr-19 16:50 
AnswerRe: Image display problem in listcontrol Pin
Victor Nijegorodov25-Apr-19 21:07
Victor Nijegorodov25-Apr-19 21:07 
GeneralRe: Image display problem in listcontrol Pin
tianzhili439925-Apr-19 22:29
tianzhili439925-Apr-19 22:29 
GeneralRe: Image display problem in listcontrol Pin
Victor Nijegorodov26-Apr-19 2:03
Victor Nijegorodov26-Apr-19 2:03 
QuestionConversion from- C++ to C-language < free(): invalid size > Pin
zak10025-Apr-19 9:14
zak10025-Apr-19 9:14 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
k505425-Apr-19 10:05
mvek505425-Apr-19 10:05 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 9:19
John R. Shaw26-Apr-19 9:19 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 10:22
zak10026-Apr-19 10:22 
Hi John & K5054,

Thanks a lot.

I have modified the code as John told me but still I am getting errors but no pointer error.

I tried changing num_cols to num_rows but it gave me following errors:
$ mpicc gaussian.c
$ mpirun -np 4 ./a.out matrix.3200.txt
[lc2530hz:5502] *** An error occurred in MPI_Scatter
[lc2530hz:5502] *** reported by process [2594701313,0]
[lc2530hz:5502] *** on communicator MPI_COMM_WORLD
[lc2530hz:5502] *** MPI_ERR_TRUNCATE: message truncated
[lc2530hz:5502] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[lc2530hz:5502] ***    and potentially your MPI job)



So I changed back to num_cols. The changed code is now:

#include <stdio.h>
#include <math.h>
#include <mpi.h>
#include <time.h>
#include <stdlib.h>
//#include <vector.h>


//using namespace std;

// Sorts the input row into chunks to be scattered two all the processors.
void sortByProcess(/*vector<double>*/double* list1, double* list2, int count);

// Swaps two rows.
void swap(double** list, int count, int row1, int row2);


int rank, size;
int main(int argc, char * argv[])
{
  double sTime, eTime, rTime;
  /*ifstream*/ FILE* inFile;
  int num_rows = 3200;
  int num_cols = 3200;
  int cur_control = 0;
  double * send_buffer = NULL;
  double * recv_buffer = NULL;
  double ** data = NULL;
  double determinant;
  char strNum_rows[20]; 
  /*vector<double>*/double* file_buffer=NULL;

  // Just get the initialization of the program going.
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  // If the input file is not given, print message and exit.
  if(argc < 2)
  {
    /*cout <<*/ printf("No input file given.\n");// << endl;
    MPI_Finalize();
    return 0;
  }
  // If the root node (0), then open the input file and read in the
  // number of rows.
  if(!rank)
  {
    printf("After rank inside  if @@@@@");
    inFile = fopen(argv[1], "r");
    fgets(strNum_rows, 20, inFile); 
    num_rows = atoi(strNum_rows);
    printf("num_rows???? =%d",num_rows);
    file_buffer = (double *) malloc(num_rows * sizeof(double *));//1

    if(file_buffer == NULL) {
       printf("malloc can't allocate memory for file_buffer");
       return -1;
    }

    /*???? inFile.open(argv[1]);
    inFile >> num_rows;
    file_buffer.resize(num_rows);*/
  }
  
  //printf("After rank outside @@@@@@@@#");
  
   send_buffer = (double *)malloc(num_rows * sizeof(double *));
   
   if(send_buffer == NULL) {
       printf("malloc can't allocate memory for send_buffer");
       return -1;
    }

  
/*?????send_buffer = new double[num_rows];*/
  //printf("After send_buffer #####@");
  // Broadcasts the number of rows to each processor.
  MPI_Bcast (&num_rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
  num_cols = num_rows / size;
  // Allocate the memory on each processor.
  //printf("After Bcast #####@");

  data = (double **) malloc(num_cols * sizeof(double *));

  if(data == NULL) {
       printf("malloc can't allocate memory for data");
       return -1;
    }

  /*???? data #####@");*/
  


  for(int i = 0; i < num_cols; i++){
  data[i] = (double *) malloc(num_rows * sizeof(double *));
  if(data[i] == NULL) {
       printf("malloc can't allocate memory for data[%d]", i);
       return -1;
    }
   }

  /* ???  data[i] = new double[num_rows]; */

  for(int i = 0; i < num_cols; i++)
  {
    for(int j = 0; j < num_rows; j++)
      data[i][j] = 0;
  }

   //printf("Before recv_buffer $$$$$$$@");
   recv_buffer = (double *) malloc(num_cols * sizeof(double *));
   if(recv_buffer == NULL) {
       printf("malloc can't allocate memory for recv_buffer");
       return -1;
    }
  /*???? recv_buffer = new double[num_cols];*/
   
  

  // Scatter the data.
  for(int i = 0; i < num_rows; i++)
  {
    if(!rank)
    {
      for(int j = 0; j < num_rows; j++){
         fgets(strNum_rows, 20, inFile); 
         file_buffer[j] = atof(strNum_rows);
      }
        /*????? inFile >> file_buffer[j];*/
      sortByProcess(file_buffer, send_buffer, num_rows);
    }
     
    //printf("After sortByProcess ^^^^^^@");

    
    // Scatters the data so that each process gets the next value for their columns.
    MPI_Scatter(send_buffer, num_cols/* NOTE num_rows gives SCATTER ERROR &deviates from original code */, MPI_DOUBLE, recv_buffer, num_cols, MPI_DOUBLE, 0, MPI_COMM_WORLD   );
    for(int j = 0; j < num_cols; j++)
    {
      data[j][i] = recv_buffer[j];
    }
  }

    //printf("After Scatter  ^^^^^^@");
   fclose(inFile);
  /*delete []*/ free(recv_buffer);
  /*delete []*/ free(send_buffer);
                //free(file_buffer);
                 /*delete []*/ //free(send_buffer);
  for(int i = 0; i < num_cols; i++)
    /*delete []*/ free( data[i]);
  /*delete []*/ free(data);
  // Begin timing.
  MPI_Barrier(MPI_COMM_WORLD);
  sTime = MPI_Wtime();

   printf("After Barrier  ^^^^^^@");
   MPI_Finalize();
    return 0;



And the errors which I am gettingare:
$ mpicc gaussian.c
$ mpirun -np 4 ./a.out matrix.3200.txt
[lc2530hz:05635] *** Process received signal ***
[lc2530hz:05635] Signal: Segmentation fault (11)
[lc2530hz:05635] Signal code:  (128)
[lc2530hz:05635] Failing at address: (nil)
[lc2530hz:05636] *** Process received signal ***
[lc2530hz:05636] Signal: Segmentation fault (11)
[lc2530hz:05636] Signal code:  (128)
[lc2530hz:05636] Failing at address: (nil)
[lc2530hz:05637] *** Process received signal ***
[lc2530hz:05637] Signal: Segmentation fault (11)
[lc2530hz:05637] Signal code:  (128)
[lc2530hz:05637] Failing at address: (nil)
[lc2530hz:05636] [ 0] [lc2530hz:05637] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7f7ac9b11f20]
[lc2530hz:05637] [ 1] [lc2530hz:05635] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7fd882900f20]
[lc2530hz:05635] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7fdeb9110f20]
[lc2530hz:05636] [ 1] [ 1] /lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7fdeb9150324]
[lc2530hz:05636] [ 2] ./a.out(+0x116c)[0x/lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7f7ac9b51324]
[lc2530hz:05637] [ 2] ./a.out(+0x116c)[0x5651bd24c16c]
[lc2530hz:05637] [ 3] /lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7fd882940324]
[lc2530hz:05635] [ 2] 56176a25a16c]
[lc2530hz:05636] [ 3] /lib/x86_64-linux-gnu/libc.so.6(./a.out(+0x116c)[0x55ee0e31b16c]
[lc2530hz:05635] [ 3] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f7ac9af4b97]
[lc2530hz:05637] __libc_start_main+0xe7)[0x7fdeb90f3b97]
[lc2530hz:05636] [ 4] ./a.out(+0xc1a)[0x56176a259c1a[ 4] ./a.out(+0xc1a)[0x5651bd24bc1a]
[lc2530hz:05637] *** End of error message ***
e7)[0x7fd8828e3b97]
[lc2530hz:05635] [ 4] ./a.out(+0xc1a]
[lc2530hz:05636] *** End of error message ***
)[0x55ee0e31ac1a]
[lc2530hz:05635] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 1 with PID 0 on node lc2530hz exited on signal 11 (Segmentation fault).
-----------------------------------------------



Somebody please guide me.

Zulfi.
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 12:31
John R. Shaw26-Apr-19 12:31 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 14:57
zak10026-Apr-19 14:57 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 17:53
zak10026-Apr-19 17:53 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw30-Apr-19 4:56
John R. Shaw30-Apr-19 4:56 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10030-Apr-19 5:48
zak10030-Apr-19 5:48 
QuestionPointer to Pointer: Conversion from- C++ to C-language Pin
zak10024-Apr-19 18:47
zak10024-Apr-19 18:47 
AnswerRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Victor Nijegorodov24-Apr-19 20:41
Victor Nijegorodov24-Apr-19 20:41 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer25-Apr-19 2:09
leon de boer25-Apr-19 2:09 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
k505425-Apr-19 7:16
mvek505425-Apr-19 7:16 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Richard MacCutchan24-Apr-19 21:36
mveRichard MacCutchan24-Apr-19 21:36 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer25-Apr-19 2:04
leon de boer25-Apr-19 2:04 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Richard MacCutchan25-Apr-19 2:46
mveRichard MacCutchan25-Apr-19 2:46 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
zak10025-Apr-19 6:52
zak10025-Apr-19 6:52 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Joe Woodbury29-Apr-19 6:38
professionalJoe Woodbury29-Apr-19 6:38 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer3-May-19 4:20
leon de boer3-May-19 4:20 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Joe Woodbury3-May-19 5:51
professionalJoe Woodbury3-May-19 5:51 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
zak10025-Apr-19 7:05
zak10025-Apr-19 7:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.