Skip to content

Instantly share code, notes, and snippets.

@galek
Last active June 27, 2017 21:33
Show Gist options
  • Save galek/a139ade00b8ef097ea984768f2b6a0b9 to your computer and use it in GitHub Desktop.
Save galek/a139ade00b8ef097ea984768f2b6a0b9 to your computer and use it in GitHub Desktop.
CHILD_FINISHED_SENDED
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pvm3.h>
#include <unistd.h>
#include <math.h>
# define SIZE 1000
# define NPROCS 5
using namespace std;
int main()
{
int mytid, n; /* my task id */
float *a,*b,*Proiz;
int me, nproc, master, msgtype;
mytid = pvm_mytid();
/* Receive data from master */
msgtype = 0;
pvm_recv(-1, msgtype);
/* receive portion of array to be summed */
pvm_recv ( -1 , -1) ;
pvm_upkint (& num_data , 1 , 1) ;
// Сразу берем всю строку
a = ( float *) malloc ( SIZE * num_data * sizeof ( float ) ) ;
pvm_upkfloat (a , SIZE * num_data , 1) ;
b = ( float *) malloc ( num_data * sizeof ( float ) ) ;
pvm_upkfloat (b , num_data , 1) ;
Proiz = ( float *) malloc ( num_data * sizeof ( float ) ) ;
// Учти, что изначельно у нас a[i][j] тут быо
for (int i = 0; i < num_data ; i ++)
{
usleep(1); // Смоделируем задержку
Proiz [ i ] = a [ i ] * b [ i ];
}
/* send computed sum back to master */
master = pvm_parent () ;
pvm_initsend ( PvmDataRaw ) ;
pvm_pkfloat (& Proiz , num_data , 1) ;
pvm_send ( master , 7) ;
pvm_exit () ;
return 0;
}
@galek
Copy link
Author

galek commented Jun 27, 2017

Поправил все на float числа.
Поправил, что бы сразу работа была со строкой

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment