# [Paradiseo-help] [PEO] Lesson 4: Parallel transformation

Mar 23 Juin 17:36:22 CEST 2009

```Dear user,

An easy way to test your pack and unpack functions is simply to display
what you pack and unpack. Taking as an example the pack and unpack
functions of lesson 4, you could write something like this (without

void pack( const Problem& _problem )
{
std::cout << "packing ... " << std::endl;
if ( _problem.invalid() )
pack( (unsigned int)0 );
else
{
pack( (unsigned int)1 );
pack(_problem.fitness());
std::cout << "fitness " << _problem.fitness()<< std::endl;
}

for (int i = 0; i < n; i++ )
{
pack( _problem.solution[i] );
std::cout << _problem.solution[i] << " ";
}
std::cout << std::endl;
}

void unpack( Problem& _problem )
{
unsigned int validFitness;
std::cout << "unpacking ... " << std::endl;
unpack( validFitness );
std::cout << "validFitness " << validFitness  << std::endl;
if ( validFitness )
{
double fitnessValue;
unpack( fitnessValue );
_problem.fitness( fitnessValue );
std::cout << "fitness " << _problem.fitness()<< std::endl;
}
else
{
_problem.invalidate();
}

for (int i = 0; i < n; i++ )
{
unpack(_problem[i]);
std::cout << _problem.solution[i]<< " ";
}
std::cout << std::endl;
}

Kind regards.

Clément Perrod wrote:
> On Mon, Jun 22, 2009 at 5:43 PM, paradiseo-help
>
>> Dear user,
>>
>> I took a look at your code and seems fine to me. Indeed, the problem may
>> come from your packing and unpacking functions.
>> Are you sure you pack and unpack correctly? I suggest you to pack and unpack
>> an individual and check that the individual has not changed. This way
>> you would be absolutely sure if this is the cause of the trouble.
>>
>>
>
> Ok. That's what I am trying to but how do you test the pack/unpack functions?
> I thought something like:
> - creation of a random solution
> - write it into a file
> - pack
> - unpack
> - write it into a file
>
> But it seems that the pack/unpack methods need MPI to work and I tried
> something like that:
> - peo::init
> - pack in NodeRank = 1
> - unpack in NodeRank = 1
> - peo::run
> - peo::finalize
>
> I tried moving the pack/unpack functions but in all the cases the
> result is the same: I have nothing to unpack.
>
> Is there any way to test the pack/unpack functions like the way I
> process or do you have any idea how to test them?
>
> Thanks,
>
>

```

Plus d'informations sur la liste de diffusion Paradiseo-help