Click here to Skip to main content
15,902,189 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Hi,
Thanks for your interest in my problem. God bless you.

I am till getting same error messages in my redirected output file. The messages are:
[lc2530hz:03857] *** Process received signal ***
[lc2530hz:03857] Signal: Segmentation fault (11)
[lc2530hz:03857] Signal code:  (128)
[lc2530hz:03857] Failing at address: (nil)
[lc2530hz:03858] *** Process received signal ***
[lc2530hz:03858] Signal: Segmentation fault (11)
[lc2530hz:03858] Signal code:  (128)
[lc2530hz:03858] Failing at address: (nil)
[lc2530hz:03859] *** Process received signal ***
[lc2530hz:03859] Signal: Segmentation fault (11)
[lc2530hz:03859] Signal code:  (128)
[lc2530hz:03859] Failing at address: (nil)
[lc2530hz:03857] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7f7c3323df20]
[lc2530hz:03857] [ 1] /lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7f7c3327d324]
[lc2530hz:03857] [ 2] ./a.out(+0x125b)[0x5581b8fa925b]
[lc2530hz:03857] [ 3] [lc2530hz:03858] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7fa90fa0af20]
[lc2530hz:03858] [ 1] /lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7fa90fa4a324]
[lc2530hz:03858] [ 2] ./a.out(+0x125b)[0x557a7d5c725b]
[lc2530hz:03858] [lc2530hz:03859] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7f157c799f20]
[lc2530hz:03859] [ 1] /lib/x86_64-linux-gnu/libc.so.6(fclose+0xd4)[0x7f157c7d9324]
[lc2530hz:03859] [ 2] ./a.out(+0x125b)[0x55dd2168325b]
[lc2530hz:03859] [ 3] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f7c33220b97]
[ 3] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f157c77cb97]
[lc2530hz:03859] [ 4] [lc2530hz:03857] [ 4] ./a.out(+0xc6a)[0x5581b8fa8c6a]
[lc2530hz:03857] *** End of error message ***
+0xe7)[0x7fa90f9edb97]
[lc2530hz:03858] [ 4] ./a.out(+0xc6a)[0x557a7d5c6c6a]
[lc2530hz:03858] *** End of error message ***
./a.out(+0xc6a)[0x55dd21682c6a]
[lc2530hz:03859] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 3 with PID 0 on node lc2530hz exited on signal 11 (Segmentation fault).
--------------------------------------------------------------------------


My modified code is:

#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");
       MPI_Finalize();
       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");
       MPI_Finalize();
       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 *));
  //calloc initializes the allocated memory to zero
  data = (double **)calloc(num_rows, sizeof(double*));

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

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


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

  /* ???  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");
       MPI_Finalize();
       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;


My compilation and execution statements are:
$mpicc gaussian.c
$mpirun -np 4 ./a.out matrix.3200.txt>output


Some body please guide me.

Zulfi.
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 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
zak10025-Apr-19 7:10
zak10025-Apr-19 7:10 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer25-Apr-19 7:49
leon de boer25-Apr-19 7:49 

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.